Skip to content

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

  1. Open the Event editor.
  2. Right click on an event.
  3. 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).


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.

Use local variable as a loop index

A local variable can be used to keep track of the current repetition number in a repeat loop. For instance, the following events create a row of 8 platforms.

Local variables can also be used within a loop, but in this case its value is reset at every repetition. For instance, the following events create 8 platforms overlapping each other.