Mod() help please, not getting it :(
ryast
Member Posts: 145
I have an attribute called "correctRun", this basically keeps getting incremented by 1 if the user gives the correct answer
eg:
game.correctRun=game.correctRun+1
I then have this rule underneath:
game.correctRun=mod(game.correctRun),20)
- display level up graphic
so I want the second rule to "fire" everytime correctRun is 20,40,60,80 etc
but for some reason the second rule fires everytime (eg: 1,2,3,4,5,6 etc) any idea what I am doing wrong?
This is the first time I am using this function in GS so I'm kind of confused.
Thanks!
(Attaching the image below as maybe I setup the rule wrong? )
Comments
Use numeric expression with mod(game.correctRun,20) = 0
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
The mod() function returns the remainder of a division problem. So mod(1,20) would equal 1 since 1 divided by 20 would be 0 with a remainder of 1.
If you evaluate both sides of game.correctRun=mod(game.correctRun,20) with a few sample values, you'll see that both sides are equal up to 19 and then unequal after that:
1=1%20=1 true
2=2%20=2 true
3=3%20=3 true
...
19=19%20=19 true
20=20%20=0 false
21=21%20=1 false
To trigger a rule at every multiple of 20, you want mod(game.correctRun,20) to equal 0, meaning that there is no remainder when dividing game.correctRun by 20.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Perfect! Thank you for the help!
I have used it in Java and PHP, but for some reason completely got it wrong in GS... could be because of lack of sleep
Cheers!
You're welcome... any other questions, just ask!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If an attribute called 'actor' belonging to an actor called 'actor' is changed to the value -100, and then this actor is constrained to linear velocity x = 'actor' then why actor of actor no go right ?
What attribute type did you use? If you used "real" that will be the problem. Real is really not real it's fake. It's a joke played on us but the GS staff try using an integer and it should all work fine.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
I used a real integer attribute value table, I used this to store the fake attributes so they didn't get injured.
Ahh! nice work around, get that into you GS the joke is back on you.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template