Can you find out if 'something' is a factor of 'something else' and how?

Started by
8 comments, last by TheCyberFlash 5 years, 5 months ago

Howdy,

I find it unlikely my title explained it properly... I want to know if I can use Wave = 0, this increments each wave... And if I could perhaps use a Switch Statement of (Wave) and have the cases check the value and find out if something is a factor.... I don't even know how to explain it -.-

Case 1, wave (find out if its a factor of 10) 

do something

Case 2, wave (find out if its a factor of 5)

do something

Case 3, wave (find out if its a factor of 2) 

do something

 

Kinda like that.. I am thinking maybe its not 'factor' maybe its 'multiple' ? I am thinking of using a Switch so on Wave 2 something happens, Wave 4 something happens again, Wave 5 something else happens, Wave 6 and 8 something happens, Wave 10 all three of them happen....

That sort of thing.. I am just stuck with the ability to check the factor/multiple stuff?? Does this help explain? Sorry, I'm terrible at this explaining thing.

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

Advertisement
38 minutes ago, CyberFlash said:

I'm terrible at this explaining thing.

Yeah :)

Not sure, but you can take the integer division remainder and check for zero

if (x % 7 == 0) // do it if x is a multiple of 7

12 minutes ago, JoeJ said:

x % 7 == 0

I think that is exactly what I need to know! Thank you :D

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

If you are using floating point (float or double) values however, you won't be able to use %. You would have to use fmod instead.

Update: I assumed C++ was in use here (bad assumption). C# allows the use of the % operator and doesn't have the fmod function. I don't know about other languages.

Nice one for the info Naruto! I forgot to specify what I am using ? I'm using Game Maker Studio, not sure on their language it just Lists GML so Game Maker Language :P I'm guna look on their docs for % - I don't think for my current situation I'll need to worry about fmod but its good to know it exists and stuff so will check that too! :) ty again

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

If you don't see a % anywhere, look for the term "mod" or "modulo", as that is what it is called. Sidenote, if you have never seen it before, the default windows calculator has a key called "Mod" in the Scientific and Programmer modes which performs the modulo function.

Update: Just searched for it myself. They have both % and mod.

https://docs2.yoyogames.com/source/_build/3_scripting/3_gml_overview/12_expressions.html

Further update (sorry for the reply spamming. Studying up a bit more on the subject):

The link above also indicates that mod and % can only be used with integer values, just like C++.

However, you can create your own fmod function for floating point values. It will look like this: (note, GML does have the floor function).


//Name this script fmod
{
	var result = argument0 - (floor(argument0 / argument1) * argument1);
    return result;
}

//Examples

var test = fmod(5.3, 2);
test will be 1.3 since 2 goes into 5 twice with 1.3 remaining.

 

1 hour ago, Naruto-kun said:

Update: Just searched for it myself. They have both % and mod.

 

Division and Modulo (div, %, mod)
div, mod (%) - Division and modulo, where div gives you the amount a value can be divided into producing only an integer quotient, while mod gives you only the remainder of a division. Note that you can only div or mod using integer values. Examples of use:

secs = time mod 60;
time_str = string(time div 60);

 

I found it! Nice :D And thanks for the fmod function too :D 

Check out my game '3NDL3ZZ: Base Defense' A simple militant styled, tower defense game.

GameDev.Net Project Page

This topic is closed to new replies.

Advertisement