How to make a timer

I want to show an object for 3 seconds. I didn’ t found, how to setup a timer. May be, there are tomatoes on my eyes. :confused:

Just add a timer event and say if the timer is greater than 3 seconds, you can either hide the object or delete as you prefer and then reset or pause the timer as you need.
In case you want each object to have it own timer, I have an example for that:
gametemplates.itch.io/template-instance-timer

But the problem is: I don’t know how to add a timer. :wink:

Click condition to add a timer event:

The event going to create a global timer with the name you enter and execute the action after the specified time.
In case you want to use the timer multiple times, you need to reset the timer after the action is executed.

But in case you want an individual timer for multiple instances, you need to create your own timer using object variables, this is what I have an example for.

There isn’t a “Create timer” action, any condition/action related to a non-existing timer will create it.
For example if you use the condition “Timer ‘MyTimer’ is greater than 5 seconds”, the first time the condition is launched a new timer called “MyTimer” will be created, reset and started; if the condition is launched again it will use the timer MyTimer instead creating a new one.
… So… be careful with the timer names!, if you make a typo in a timer name, GD will just create a new timer with the typo as name, and you’ll never be warned :smiling_imp:

It doesn’t work.
At first: excuse my english. And: I’m a beginner, a pensioned teacher and I want to make a training game in mathematics for pupils in primary school.
I use GD4.
So, here is a screenshot: download/file.php?mode=view&id=3806
Timer1.JPG
Condition 10/1 is deactivated.
If the cursor touch “Neues Objekt3” then nothing happens, but after 3 seconds the object appears and will never hide. If I deactivate condition 11 and let 10/1 deactivated and then touch “Neues Objekt3”, the object instantly appeares and is to see up to the end of the world.
Where is my mistake?

Sorry for my english :frowning:

I think the problem is the initialization of the timer.
I will code after “show object”: Reset a timer “Lob”.

First of all, when you are using a timer event, unless you have paused the timer before, the timer will be running from the beginning unless you pause it and it value will be constantly increasing unless you reset the timer and it will constantly hide the object because the value of the timer is constantly greater than 3.
Also not sure why you need a Lob variable there but as long you don’t set the value of the Lob variable back to 0, it is going to constantly show the object because the variable is 1 so it is true and execute the action to show the object.

I think this two mistake causing the bug but maybe there are other events interfere as well that we don’t see.

Let me show you how I would be doing, it might help to get the idea.

The events in GDevelop are being triggered every frame (60 times a second) and execute the actions and sub-events the same amount of time as long the condition is true. So you need to take this in to account when you plan how you want things to be executed.

Also, to avoid errors and scare beginners with error messages, GDevelop trying to help a little and in case you are using a timer or variable that doesn’t exist yet, instead of throwing an error, GDevelop is go ahead and create it for you. So, in my example when I Pause the timer At the beginning of the scene, basically GDevelop going to create the timer for me because it is doesn’t exist and pause it right at the beginning so later when I check if the timer is greater than 3, the timer will be already initialized but not running. To run the timer it need to be unpaused and this is what I would be doing when the mouse/touch is on the object…

To add to what ddabrahim said, this is what your events look like to GDevelop on the very first loop through the events:

9 - Cursor isn’t on Neus Objekt3, so do nothing
10 - Variable Lob isn’t 1, so do nothing
11 - Timer Lob doesn’t exist. Create timer Lob and start it running

This loop will continue doing nothing until 3 seconds has passed or the cursor is on Neus Objekt3.

When 3 seconds have passed, event 11 will hide object Neus Objekt2, but if the cursor is on Neus Objekt3 then it will be made visible again by event 10, then hidden again by event 11, then made visible again by event 10 and so on. The object is constantly being hidden, then shown again, too fast for you to see what is happening.