Rounding Numbers. How do I do that?

help

#1

I would like to use a rounding technique for my tapper game. How do I do that?


#2

Use this! :smile::smile: (weird, exact same situation🙃🙃🙃...)


#3

There is no direct INT() or ROUND() function in Hopscotch. Still, there are hacks. And our old friend, the invisible hack-helper object is what can do it for you.

For example, we can use any of the properties that force an integer value on the things they're given... like... position to get rid of the decimal part of a number. Set it with the decimal value, then read it back, and it'll be an integer. To "round", you might have to add "0.5" to your value first, but you get the idea...


#4

If the numbers less than 5, round down, if it's 5 or more, round up
Hope that helps:laughing:!


#5

I posted a question about this on stackoverflow awhile ago, and the lead developer of Hopscotch actually responded with a neat trick:


Here is what she said (Again, all her thinking, her images, her words, complete credit goes to her):

"The repeat block will round your number to an integer. So if you repeat times the original number and increment a test number, you can check if they come out equal at the end."

"As others have mentioned, for this to work the original number needs to be positive. To solve for this just multiply by -1 if the original number is less than 0."

In this case she set the variable 'integer' to 55/6, but that number is just the number you want to check if it is a decimal or not, and you can set it to whatever you want.


#6

Hey, I'm doing the same thing. @CreativeCoder let me know how to do this: here's what you do

When Object is tapped etc.:
Increase "Cost" by one
Set value "Round" to zero
Repeat times "Cost"
Increase "Round" by 1
End
Set value "Cost" to "Round"

Because Hopscotch can't repeat times as a decimal (What, do half the code?), it Rounds it in the end. Hope this helps!