LuaRules.wiki
author Wuzzy
Sat, 06 Jan 2024 14:10:36 +0000
changeset 2265 5d951acf9b54
parent 2195 f9dc7606394c
child 2266 eba9a043a81e
permissions -rw-r--r--
LuaRules: Add math.random rule

#summary List of development rules for scripts

= Scripting Rules =

For scripts, there are some basic but important development rules that all scripts need to follow to ensure the scripts are compatible across multiple systems.

For behavior in your script that affects actual gameplay, there are restrictions of what you can do with numbers. These are the rules:

 * Only integer numbers are allowed; floating-point numbers are forbidden
 * If you divide, divide by powers of 2 if you can
 * If you want to divide by a different integer value, use the `div` function for integer division
 * Keep your numbers within ±2<sup>53</sup>
 * Avoid `math.floor` and `math.ceil`
 * Never use `math.random` for gameplay-relevant numbers like setting the position, use `GetRandom` instead

These restrictions on numbers don’t apply to numbers that you don't use for gameplay but for stuff like harmless eye candy. For example, you can use `math.random` safely as long you don’t use the generated numbers for anything that affects gameplay.

Failing to follow these rules might lead your script to behave differently on different systems, leading to desynchronization bugs, which means they will not work online.