Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: MachineElf on Wed 16/07/2003 23:21:27

Title: Modulo (%) operator?
Post by: MachineElf on Wed 16/07/2003 23:21:27
Isn't the modulo operator (% in C and C++) implented in AGS? Why? Even if most people will probably never use it but I think it would be useful.

(Sorry for posting so much here the last few hours, but I've just gotten around doing a little advanced stuff with AGS again...)
Title: Re:Modulo (%) operator?
Post by: Gilbert on Thu 17/07/2003 02:19:50
I think that's just because it's a game environment, not a full programming package. If many people find it useful, I think this can go into the list, as it's not a difficult thing after all. Currently you can do this via:

modx = y - ((y/x)*x);

to get say y mod x .
Title: Re:Modulo (%) operator?
Post by: MachineElf on Thu 17/07/2003 12:18:39
So that actually works in the engine? This would mean the engine treats the y/x division as a float, which AGS normally doesn't support, right?
Title: Re:Modulo (%) operator?
Post by: Pumaman on Thu 17/07/2003 20:48:48
No, the reason it works is because it's not treated as a float.

For example, 5 mod 3 (which equals 2).

modx = 5 - ((5 / 3) * 3)
= 5 - (1 * 3)
= 5 - 3
= 2
Title: Re:Modulo (%) operator?
Post by: MachineElf on Thu 17/07/2003 22:01:06
Ah! Of course! *epiphany*
Thanks!