Sorry my math skills are awful :\ I'm trying to make a point system where my player gets a 1-UP for every 10,000 points gained. What expression do I use for this?
Printable View
Sorry my math skills are awful :\ I'm trying to make a point system where my player gets a 1-UP for every 10,000 points gained. What expression do I use for this?
a method i always use for this is this:
whenever a score is added (to counter or score)
also have a counter used to track hiscores, and add it here too.
so each time add the score gained to both counters; or score & counter.
then check hiscore counter >10,000 and subtract 10,000 and add a life.
the score will stay as normal adding up all the time. its the hiscore that you keep checking with.
Always set lives to score mod 10000
i see mod used now and then. i still dont understand exactly how it works - sounds silly, but mod didnt exsist when i was at school.
ive tried to look it up, but i get examples etc, which looked garbled to me.. yeah im not a bright spark ;)
can someone explain it in "simpleton" terms :P
Jacob has the right idea using mod, but the wrong expression
Using mod, I recommend:
Score MOD 10000 = 0
- Add 1 to lives
Explanation of MOD: MOD gets the remainder from a division
eg. if 10001 mod 10000 (What's the remainder from 10001/10000)?
- remainder is 1, therefore not 0, so don't add a life
if 20000 mod 10000 (remainder from 20000/10000)
- remainder is 0, therefore add a life
Jacob's expression just changes the lives to the remainder... therefore lives always match the score until it reaches 10000, then it goes back to 0. Not exactly useful for a lives counter, but he was on the right track.
You'll also need to use a flag so it doesn't loop over and over again for the same score.
eg.
Score MOD 10000 = 0
AND Score is not equal to Previous_Life_Added_At_Score
- Add 1 to lives
- Set Previous_Life_Added_At_Score to Score
However, using MOD introduces the problem that if the score isn't incremented by 1 then it could skip the new life entirely (eg. if you add 7 to the score, instead of 1). The first reply is probably a better way to work around this problem.
O_o see you've just confirmed my thoughts.