Nice smooth timer
I_AM_BENJI
USAMember Posts: 40
I have been having trouble make a time counter. I want some thing that goes up by .01. I tried use a timer and an attribute saying every .01 seconds add .01 to attribute, but when i do this there are a bunch of other random numbers after as well. Like so 4.45999999 Does anyone no any other methods.
Comments
I believe the fastest timer would be every 0.03 seconds but regardless of that, you can use the roundTo() function to round a number to a certain number of digits. So roundTo(4.45999999,2) would give you 4.46.
This behavior:
Results in these log values:
Log(Actor: Actor 1): 0.02
Log(Actor: Actor 1): 0.05
Log(Actor: Actor 1): 0.08
Log(Actor: Actor 1): 0.12
Log(Actor: Actor 1): 0.15
Log(Actor: Actor 1): 0.18
Log(Actor: Actor 1): 0.22
Log(Actor: Actor 1): 0.25
Log(Actor: Actor 1): 0.28
...
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang but where exactly do i put the log statement in??
Use:
roundTo(Game.time,2)
EDIT: whoops, didn't read tatiang's post, basically what tatiang said.
You don't need to put it anywhere ! In the above example it is just used to show how the formula works.
You don't need a Log Debugging Statement. That's just for debugging purposes. You would replace that statement with whatever behaviors/rules you want to run every timer cycle.
Edit: actually, you'd need a custom timer if you want to make sure the timer is running on a rounded number. But... what is the purpose of your 0.01 timer? Are you displaying it on the scene? If so, use the roundTo() function like I mentioned.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If he is making a game timer he won't need the timer behaviour, or any attributes, he can just display (or track in a rule) your roundTo(Game.time,2) formula.
Lol, true... no need for a timer. Anyway, I guess we need more details...
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang @Socks
Thank you guys
I guess i am just a noob at this. So yes I am displaying the time through an actor. So anything??? How would i display the time?
Just put roundTo(game.Time,2) in a Display Text behavior. Be sure to select game.Time from the attribute browser in the expression editor. Don't just type it in.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
game.time keeps running even after pausing scenes and such, its best to display self.time with an actor that is there when he wants the timer to start.
Fortuna Infortuna Forti Una
@tatiang
i got that but now it looks glichy because it is centered and changes from something like 3.47 to 3.5
Then don't have it centred ?
Oh i totally new that (not)
THANKS
he was talking about my attribute
You could use padReal() to force the display of two decimal points:
padReal(game.Time,1,2)
It will still "jump" when the integer value (in front of the decimal point) changes length but that's not as often or abrupt as with decimals.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User