Increase number text of item count incrementally?

This seems like something that happens in most games, where if you pick up (collide with) a money object, for example, the UI text showing your total money will increase incrementally rather than just instantly adding to the total.

For example, if I’m remaking the original Legend of Zelda for NES and the player picks up a blue rupee, it’s worth 5 rupees. Say you currently have 0 rupees, and your rupee count in the UI likewise shows 0. I increase the global variable RupeeCount by adding 5 once the collision occurs, but this instantly changes the UI rupee count number to 5, rather than counting up incrementally: 1, 2, 3, 4, 5.

I tried using a Repeat condition, repeating the global variable +1 action 5 times, but it still seems to instantly increase the amount since I think the loop executes so fast that you can’t see the rupee count number increasing incrementally.

Can someone explain how you would get the effect of picking up a blue rupee, then having your rupee count increase 1, 2, 3, 4, 5 rather than instantly changing it to 5? Hopefully I explained that well enough. If you need any clarification, let me know.

Here is the current code I’m using in place of this, to simulate the “Refill Loop” sound lasting for the amount of time it would take for the incremental increase 1, 2, 3, 4, 5 to take place:

Keep 2 values for rupees - the actual value and the display value - and a timer. Start the timer at the beginning of the scene. When you collect a blue rupee, increment the actual value by 5. Then have a condition that if the display value is less than the actual value and the timer is greater than 0.2, then increase the display value by 1 and reset the timer.

1 Like

Thank you very much for your response, MrMen. I’ll give that a try and come back if I’m having further trouble. It seems like for as many games that have that feature, it’s a rather roundabout thing to implement.

Should I use a scene timer or an object timer (for the text object for the rupee display count) to make this work?

Or you can use a tween on your variable.

Interesting. How do you go about using a tween on a text object which is displaying the string of a number variable? What if the number you’re trying to incrementally decrease is a global variable, rather than an object variable?

You have to assign a object variable to the text. Apply a tween behavior to the text and then use “tween object variable” as action. i.e.: fromm 0 to 50 and time in ms. I don’t think you can tween a variable other than object variable.

You can tween a scene variable:


@tjv189, using a tween as @zutty suggested is another way. Instead of a timer, check if the tween has finished and if it has, remove it and kick off another tween on the display value if it is still less than the actual value.

Thanks. I didn’t know that. Never used it.

I tried to make an example but it doesn’t work anymore the way I used to do,
Why does the top code works and the bottom doesn’t?
The top one is from a downloaded example file.

Not sure. What does it show? do you have more than one MyText object ont he screen?
The two do seem to use slightly different tweens (the from value in the top is not present in the bottom example).

However, I’ve recreated your bottom example, and it works fine. It only works once though - after that var is 1000 an won’t increase any more.

I have only one instance of MyText. It waits the 10000ms and change instantly to 1000 not showing the animation.

The top image is from the downloaded file. It has the field “from”
The bottom one is what I made. It hasn’t.
I noticed that if from the top screen, I click in another option and come back to that same option, the field “from” doesn"t appears anymore and the code doesn’t work like it did.

I got the desired effect working with a scene timer. Thank you so much for your solution above.

Can you help clear one thing up for me though? Is there a rule of thumb for when to use a scene timer over an object timer? I’m kind of getting confused as to which timer is best to use for certain situations.

Also, if you use a scene timer, and it is running, when you change scenes will that timer continue running? Or will it only run on the scene in which you started it? Thanks again.

Object timer refers only to the object you applied it. Scene timer takes in account all objects in the scene. If you change the scene you need to create another scene timer. It works only in scene it was created.

I’m going to put my doubt about the tween issue in another topic I have created in case adm wants to close this one. Thanks.

Perhaps I should start another topic with this question, but with what you said, is it even possible to have a “Global Timer”? In other words, a timer that will continue running between scenes?

If not, how would you track something like the player’s total play time?

If the timer is specifically for an instance of an object, and there are multiple instance of it on the scene, then an instance timer would be the best option. Something like a delay before the object moves or performs another action.

For a single instance object, like a score, then a scene timer could be used.

It will only run while the scene it was started in is active. I’m not sure what happens if you pause the scene, start another and then go back to the original scene - that’s something you may have to play round with to figure out.

No, there are no global timers. But you can get the current time in the first scene into a global variable:


and then check the elapsed time in another scene:


Note, timestamp will be in milliseconds. If you want whole seconds, you can divide by 1000 or use Time("sec").

1 Like