Variable

Variable

> Tutorial

Variables are a fundamental point in all programming languages. They are used to store values in order to reuse them in calculations.

The variables proposed by the LeekScript can contain several types of value:

Creating a variable

To use a variable, it must be declared beforehand. This declaration is made using the var keyword as follows:

// We declare the "enemy" variable var enemy

It is also possible to assign a value to your variable in the following way:

// Declare the enemy variable and assign it the closest enemy var enemy = getNearestEnemy()

Using a variable

You can use variables in your code in different ways.

They can be assigned a value (i.e. made to “retain” this value in memory) using the = assignment operator:

// We declare myVariable var myVariable // We assign the value 5 to myVariable myVariable = 5