I want a trigger to run each time my integer reaches 5, 10, 15, 20, 25 etc... For that, I'm using an if then else action and I COULD just make a lot of conditions, but I'd like to keep it neat. So is there any mathematical condition I can use to verify whether an integer divided by 5 = a true number?
You want to make sure X is evenly divisible by 5, right? X mod Y gives the remainder of X / Y, so in this case you want the remainder to be 0. Unless I'm not understanding your question correctly. By "true number" you mean integer, right?
mod extracts the reminder.Reminder is a part of the number which can not be devided without causing fractions <1.
3 can't be devided by 5, so reminer is 3.
10 can be devided by 5, so reminder is 0
11 = 10 + 1 = 5 + 5 + 1, 10 is devidable, 1 is reminder
14 = 10 + 4 = 5 + 5 + 4... and so on
Also, as far as I was told, counting up an additional variable to 5 is more performant for most applications, because addition is way easier to do for a computer than division, which is done internally for mod.
Also, as far as I was told, counting up an additional variable to 5 is more performant for most applications, because addition is way easier to do for a computer than division, which is done internally for mod.
Usually, if you use mod, you use it within a loop. You want something to only be executed every 5th tick of the loop, for example. So you could do this:
Same effect, but only an increment on every tick, instead of a "costly" mod call.
Keep in mind, that this is probably entirely irrelevant for your application, it most likely won't make any significant difference. Also, I have no sources on this, its just, what someone told me when I was using mod the same way (but it sounds logical to me ;) )
Your statemente isnt entirely accurate Kueken, specially when you add an extra variable to the stack and two extra operations (+ + operator doesnt exist in galaxy iirc). A bitwise and would be actually faster than your operation. Details: http://en.wikipedia.org/wiki/Modulo_operation#Performance_issues
Your statemente isnt entirely accurate Kueken, specially when you add an extra variable to the stack and two extra operations (+ + operator doesnt exist in galaxy iirc). A bitwise and would be actually faster than your operation. Details: http://en.wikipedia.org/wiki/Modulo_operation#Performance_issues
Quote:
For example, the modulo of powers of 2 can alternatively be expressed as a bitwise AND operation
Bitwise and only works for powers of 2, for other numbers it is more complicated. However you might still be correct, that setting the additional variable might be worse than using modulo, I don't know. Also I used galaxy++ script, the ++ will of course be translated to +=1.
I want a trigger to run each time my integer reaches 5, 10, 15, 20, 25 etc... For that, I'm using an if then else action and I COULD just make a lot of conditions, but I'd like to keep it neat. So is there any mathematical condition I can use to verify whether an integer divided by 5 = a true number?
@Neonsz: Go
X mod 5 = 0
I'm not sure how MOD comes up in the editor, but I'm sure it's there.
EDIT: "Math - x mod y" according to http://www.sc2mapster.com/wiki/galaxy/triggers/modulo-integer/
@Khaztr: Go
How come it's X mod 5 = ZERO?
@Neonsz: Go
You want to make sure X is evenly divisible by 5, right? X mod Y gives the remainder of X / Y, so in this case you want the remainder to be 0. Unless I'm not understanding your question correctly. By "true number" you mean integer, right?
@Khaztr: Go
Yea, I'm not familliar with the english term, but I guess it's called integer. I'll try it out, thanks for your help!
X mod 5 determ the rest of the integer division of X divided through 5.
Examples:
3 mod 5 = 3
10 mod 5 = 0
11 mod 5 = 1
14 mod 5 = 4
15 mod 5 = 0
1337 mod 666 = 5
and so on.
where did you get those numbers? :p
3 / 5 = 0.6 so mod = 6
11 / 5 = 2.2 so mod = 2
14 / 5 = 2.8 so mod = 8
1337 / 666 = 2.00(750) so mod = 00(750)
or is not how it works ? :p
EDIT: actually it does not. lol and i thought it works that way.
mod extracts the reminder.Reminder is a part of the number which can not be devided without causing fractions <1.
3 can't be devided by 5, so reminer is 3.
10 can be devided by 5, so reminder is 0
11 = 10 + 1 = 5 + 5 + 1, 10 is devidable, 1 is reminder
14 = 10 + 4 = 5 + 5 + 4... and so on
it's elementary school math
Also, as far as I was told, counting up an additional variable to 5 is more performant for most applications, because addition is way easier to do for a computer than division, which is done internally for mod.
Could you explain that further?
Usually, if you use mod, you use it within a loop. You want something to only be executed every 5th tick of the loop, for example. So you could do this:
Or you can do this:
Same effect, but only an increment on every tick, instead of a "costly" mod call.
Keep in mind, that this is probably entirely irrelevant for your application, it most likely won't make any significant difference. Also, I have no sources on this, its just, what someone told me when I was using mod the same way (but it sounds logical to me ;) )
Your statemente isnt entirely accurate Kueken, specially when you add an extra variable to the stack and two extra operations (+ + operator doesnt exist in galaxy iirc). A bitwise and would be actually faster than your operation. Details: http://en.wikipedia.org/wiki/Modulo_operation#Performance_issues
Go play Antioch Chronicles Remastered!
Also, coming soon, Antioch Episode 3: Thoughts in Chaos!
Dont like mapster's ugly white? Try Mapster's Classic Skin!
Bitwise and only works for powers of 2, for other numbers it is more complicated. However you might still be correct, that setting the additional variable might be worse than using modulo, I don't know. Also I used galaxy
++
script, the++
will of course be translated to +=1.In a separate operation, alas.
Go play Antioch Chronicles Remastered!
Also, coming soon, Antioch Episode 3: Thoughts in Chaos!
Dont like mapster's ugly white? Try Mapster's Classic Skin!