Local variables
Local variables are variables which are:
- stored in memory for the duration of an event execution,
- can only be accessed from its event and sub-events.
They're useful for temporarily using the result of a calculation. For instance, to generate random number and use it to trigger different actions according to its value.

Local variables are deleted from memory as soon as their event is fully executed (including its sub-events).
Creating local variables
- Open the Event editor.
- Right click on an event.
- Select Add > Add local variable.
In the editor, choose "Add a variable", then enter a name, choose a data type and, optionally, enter a default value for the variable (this will be the value used when the even execution starts).
Tip
Variable names should not contain dots (periods), commas or spaces. Other characters are also reserved by GDevelop. If you use something forbidden, GDevelop will automatically correct the name you've entered.
Using local variables in expressions
You can use local variables in expressions. Just write the name of the variable to use it in a formula. Note that if an object is using the same name, the object will take priority over the local variable.
Local variables in loop events
Local variables are supported in all loop events: While, Repeat, For Each, and For Each Child Variable. Local variables declared in a loop event are scoped to the loop and accessible within its sub-events.
Tip
All loop events also support a loop counter variable — a built-in variable that starts at 0 and auto-increments by 1 on each iteration. This removes the need to manually manage a counter variable.