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

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
12 minutes ago, JoeJ said:

x % 7 == 0﻿

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

##### Share on other sites

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.

Edited by Naruto-kun

##### Share on other sites

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.

##### Share on other sites

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 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

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites
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 And thanks for the fmod function too

## Create an account

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015749
×