How to spawn an actor every 10 points
Doguz
Member Posts: 500
I'm terrible at this sort of stuff.
Everytime the score clicks over another 10 points I'd like to spawn an actor. How please? I know it's a simple equation, I'm just not knowledgable.
-Thanks
Everytime the score clicks over another 10 points I'd like to spawn an actor. How please? I know it's a simple equation, I'm just not knowledgable.
-Thanks
Best Answer
-
tatiang Posts: 11,949It depends a bit on how you're keeping score. If you have a game that counts up slowly from 0 to 1 to 2, etc., then you would create an integer attribute called game.ZERO and give it the value 0, and then use this rule:
When attribute game.ZERO=mod(game.score,10)
[spawn an actor]
The mod() function is a math function that returns the remainder from a division problem. So if you divide game.score by 10 and the remainder is zero, then you want to spawn an actor (5÷10 = 0R5; 10÷10=1R0; 20÷10=2R0; 23÷10=2R3; etc.).
However, if you are adding points quickly or not increasing them by a factor of ten (1, 2, 5, 10), then that rule won't work. For example, if you have 0 points and then increase to 5 and then to 28 and then to 6004, that rule will never fire because none of those numbers are evenly divisible by 10.
So the question becomes: do you want to spawn an actor once the score is 10 or more points higher than the current score? Or do you want to spawn one actor for every 10 points? The difference is that if you go from 28 to 6004, you would either spawn one actor or hundreds. For the former, you could do this:
When attribute game.score > gamelastScore + 9
[spawn an actor]
change attribute game.lastScore to game.scoreNew to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
My scoring is adding by 1 mainly but can add by 2,3,5 or 10 if they power up on certain objects. I'll see how this goes.
Thanks again. Never used the mod operator before.