Rounding Numbers
games4fun
Member Posts: 185
Hello,
How can I round the value of a attribute based on its value. So if value is over 51 round up if value under 50 round down.
Ex
If attribute value is 220 round to 200
If attribute value is 951 round to 1000
If attribute value is 910 round to 900
How can I round the value of a attribute based on its value. So if value is over 51 round up if value under 50 round down.
Ex
If attribute value is 220 round to 200
If attribute value is 951 round to 1000
If attribute value is 910 round to 900
Comments
If value is equal to more then 249 change value to 200
If value is more then 249 change value to 300
Repeat process for how high you need to go.
Working on a simplied version now, will see how I go.
Here is what I did
When touch is pressed
Change "rounder" (has to be a integer Boolean) to "score"/100
Change "score" to "rounder"*100
How it works:
Example:
If your score is equal to 356
You then are changing rounder to 356/100
Since that's going to give you a decimal answer you have to use Interger Boolean for "rounder", as they automatically round up or down so they don't display any decimals.
So it's going to say that the answe is 4, hence it rounded up from 3.56.
Your then changing your score to 4 * 100 since you are wanting it rounded up in hundreds (which Is why you divided by 100 as well)
That's it
Hope it helps and is what your looking for.
Thanks alot
So if final number was 1000. Then take 1000 and randomize it to a percent between 10 and 50. So lets say 17 percent so it would then be 170 and then round 170 to 200.
Hopefully that makes sense.
If 50 < mod(game.value,100)
.....change attribute game.value to ceil(game.value/100)*100
Else
.....change attribute game.value to floor(game.value/100)*100
This is exactly how you can snap actors to a grid. If your grid spacing is 100, then the above rules will snap at every 100 pixels assuming you use self.position.X or self.position.Y as the attribute in place of game.value.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User