The Mugen Fighters Guild

M.U.G.E.N Central => FullGame development => MFG Presents Street Fighter => Topic started by: Just No Point on June 06, 2014, 06:54:39 pm

Title: Random Coding inquiries thread
Post by: Just No Point on June 06, 2014, 06:54:39 pm
Code:
trigger2 = var(14) % 50 = 1 

Quote
%

The remainder or mod operator. If x and y are both ints, x%y returns an int representing the remainder after performing a division x/y. For instance, 7%2 = 1, and 23 % 17 = 6. It is an error to use the % operator on float values, or to compute x%0. The result of such operations will be discussed in the section on SC values.

This is from Rajaa's Necro. I'm studying how he made the config file and what all the pieces do. Right now I'm looking into his chaining coding.

What exactly does the % here do exactly? (Arkansas math was horrid when I was a kid, we didn't learn this crap)

Here is the full code it came from though I don't think you'll need it to explain
Spoiler: from CMD (click to see content)

Title: Re: Random Coding inquiries thread
Post by: Alex Sinigaglia on June 06, 2014, 06:58:24 pm
From his example:
7/2 = 3, you get 1 as a remainder/rest.
23/17=1, you get 6 as the remainder/rest;

from the cmd:
var(14)/50 = you get a result that we don't care about in this instance, but you get the rest (it's 1, or 2, or 4, or 5).

so the % does the division and tells you the rest of the operation.
Title: Re: Random Coding inquiries thread
Post by: DKDC on June 06, 2014, 07:02:27 pm
Basically, for A%B=C, you take A, keep subtracting B until you can't anymore, and what's left is C. Var(40)%50=1 is true when var(40) has the value 1, 51, 101, 151 etc. C can't be a number higher than B.
Title: Re: Random Coding inquiries thread
Post by: Just No Point on June 06, 2014, 07:05:24 pm
Oh okay, I think I get it now! Won't know for sure till I apply it myself but that won't be today =p

Makes sense in my head though and as we've seen that's always a good sign! /sarcasm
Title: Re: Random Coding inquiries thread
Post by: XGargoyle on June 06, 2014, 07:19:16 pm
You will commonly use the mod operator for something that you want to trigger at a fixed and continuous interval, for example gametime%60=0 will trigger once per second, exactly on game tick 60, 120, 180, 240...

gametime%60=1 will trigger on tick 61, 121, 181, 241...

When using it in a variable, var(x)%10=0 will trigger every time var(x) increases or decreases 10 units