Advertisement Jump to content
CyberFlash

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


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 :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

Share this post


Link to post
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.

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

Share this post


Link to post
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 this post


Link to post
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 :D And thanks for the fmod function too :D 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!