> LeekScript v2
**Attention, this page is intended for users of LeekScript 2, to inform you about the variables in the current version of LeekScript, please go to Les_Variables**
Works:
----- What is a variable?
Variables are a fundamental point in all programming languages. They are used to store values ((results of expressions)) in order to reuse them in calculations ((other expressions)).
The variables proposed by the LeekScript can contain several types of value: ((place links to specific pages if needed, rather than mentioning later))
However, the type of the variable is not fixed (like in C or Java) but adapts to the data that you want to store in it (like in JavaScript or PHP).
((There is no adaptation, the type is simply checked on each use.))
To use a variable, it must be declared beforehand. ((Beware of the wording, suggests that the variable can only be assigned afterwards, causes problems with let and const. Reverse this example and the next.) ) This declaration is made using the “var” keyword as follows:
// We declare the nomDeVariable variable var variableName;
It is also possible to assign a value to your variable in the following way:
// We declare the nomDeVariable variable and assign it the value 12 let variableName = 12;
Note that you can also declare several variables by separating them with a comma:
// Declaration of firstVariable and secondVariable var firstVariable, secondVariable; let firstVar = 1, secondVar = 2
Note: The ; became optional with the move to LSv2. It is still useful for those who want to clarify unreadable code.
((The indentation makes it more readable, the semicolon clarifies ambiguities for the compiler/interpreter.))
There are 4 different types of variables. They are characterized by their ability to be modified and to last in combat. So we have :
Type of variables Changeable Constant End of round var let End of fight global const
These variables are declared in the same way, but once a constant variable is declared, it won't be much ((absolutely not at all, unless there is some weird behavior with collections/anonymous objects.)) modifiable (logic) .
((Move the examples from the var section that can be used with let, into this section.))
((Show examples that deal with justified reassignment, for example, with loops.))
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:
((What is presented is reassignment, specific to var and global.))
// We declare myVariable var myVariable // We assign 1 to myVariable myVariable = 1
It is possible to perform calculations by writing expressions, you can use the following operators:
We proceed as follows:
((It's a bit dirty to always reuse the same variable, beginners shouldn't write dirty code. Psst: let))
// Declaration of variable a go to // Do some calculations a = 2 + 8 // a takes the value 10 a = 5 - 4 // a takes the value 1 a = 3 * 5 // a takes the value 15 a = 6 / 2 // a takes the value 3 a = 8% 3 // a takes the value 2
// But we can also combine the operators a = 1 + 2 * 3 // a takes the value 7 a = 4 / 2 + 1 // a takes the value 3
// And even use parentheses a = (2 + 3) * 2 // a takes the value 10
You can also use a variable in an expression, its value will be used to perform the calculation. For example
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.