Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fr:gdevelop5:all-features:expressions [2019/03/08 14:51] (current)
bouh created
Line 1: Line 1:
 +FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)//
  
 +# Writing expressions
 +GDevelop supports expressions! Expressions are dynamic values that can be used in event parameters. For example to set an object position, ​ you can use a fixed number as ``75`` or you can use an expression such as ``AnotherObject.X() - Variable(position_offset)``.
 +
 +There are two types of expressions:​
 +
 +  -  //​**Numerics**// ​
 +
 +Numerics can be used in event parameters. They receive a numeric value such as object position, z-order, variable number, etc.
 +
 +  -  //​**Strings**// ​
 +
 +Strings can be used in parameters that receive a text/string value. You can use this expression to read the content of a text object string, its color, the text of another variable, etc.
 +
 +## Numeric expressions
 +As stated above, Numeric expressions can be used in numeric parameters.
 +
 +### Random values
 +
 +``Random(max)`` - Returns an integer between `0` and the `max` value that is defined. ​ The "​range"​ is [0, max].
 +
 +//Examples using the Random() Expression://​
 +<code Javascript>​Random(3) ​ // The 3 possible integer values are 0, 1,  2,  and 3
 +</​code>​
 +
 +``RandomInRange(min,​ max)`` - Returns an integer between `min` and `max`. ​ The "​range"​ is [min, max].
 +
 +//Examples using the RandomInRange() Expression://​
 +<code Javascript>​RandomInRange(-1,​ 2) // The 4 possible values are are  -1, 0, 1,  and 2  ​
 +
 +// Note that "​RandomInRange(min,​ max)" is equivalent to "min + Random(max - min)":
 +-1 + Random(2 - -1) // This gives the same results as above
 +</​code>​
 +
 +``RandomFloat(max)`` - Returns a float between `0` and `max`. ​ The range is ``[0, max)``. Note that ``max`` is not included in the range. It's important to also note that the possible results are infinite. This is because there are infinite real numbers between any two different values.\\
 +
 +//Examples using the RandomFloat(max) Expression://​
 +<​code>​RandomFloat(2.5) //SOME of the many possible values are 0, 1.467798, 2.000587, and 2.499999</​code> ​
 +
 +``RandomFloatInRange(min,​ max)`` -  Returns a float between `min` and `max`. ​ The range is ``[min, max]``. Note that ``max`` is not included in the range. It's important to also note that the possible results are infinite as there are infinite real numbers between any two different values.\\
 +
 +//Examples using the RandomFloatInRange() Expression://​
 +<​code>​RandomFloatInRange(-1.5,​ 2) //SOME of the many possible values are -1.5, -0.598156, 1.000874 and 1.99999</​code>​
 +
 +
 +``RandomWithStep(min,​ max, step)`` - Returns a number between `min` and `max` in steps. The range is ``[min, min + N*step]`` with ``min + N*step ≤ max < min + (N+1)*step``. It means it can return any of the stepped values that are less than or equal than ``max``.\\
 +
 +//Examples using the RandomWithStep(min,​ max, step) Expression://​
 +
 +<​code>​RandomWithStep(1,​ 3, 0.6) // The generated numbers are ``1``, ``1.6``, ``2.2`` and ``2.8``</​code>​