LuaRules.wiki
author spudpiggy <facetakers@gmail.com>
Fri, 05 Apr 2024 11:35:26 +0100
changeset 2269 7a834d2cb993
parent 2268 3befe2d2bf3b
permissions -rw-r--r--
Added all fallbacks; previously there were some missing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2191
aade57b7b63e LuaRules: cleanup
Wuzzy
parents: 2189
diff changeset
     1
#summary List of development rules for scripts
aade57b7b63e LuaRules: cleanup
Wuzzy
parents: 2189
diff changeset
     2
aade57b7b63e LuaRules: cleanup
Wuzzy
parents: 2189
diff changeset
     3
= Scripting Rules =
2189
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
     4
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
     5
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.
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
     6
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
     7
For behavior in your script that affects actual gameplay, there are restrictions of what you can do with numbers. These are the rules:
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
     8
2192
edf132b3d2b8 LuaRules: fix bullet
Wuzzy
parents: 2191
diff changeset
     9
 * Only integer numbers are allowed; floating-point numbers are forbidden
edf132b3d2b8 LuaRules: fix bullet
Wuzzy
parents: 2191
diff changeset
    10
 * If you divide, divide by powers of 2 if you can
edf132b3d2b8 LuaRules: fix bullet
Wuzzy
parents: 2191
diff changeset
    11
 * If you want to divide by a different integer value, use the `div` function for integer division
2195
f9dc7606394c LuaRules: plusminus
Wuzzy
parents: 2192
diff changeset
    12
 * Keep your numbers within ±2<sup>53</sup>
2192
edf132b3d2b8 LuaRules: fix bullet
Wuzzy
parents: 2191
diff changeset
    13
 * Avoid `math.floor` and `math.ceil`
2267
bbc87ef05898 LuaRules: Grammar
Wuzzy
parents: 2266
diff changeset
    14
 * Don’t use `math.random`, use `GetRandom` instead
2189
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
    15
2268
3befe2d2bf3b LuaRules: Italic
Wuzzy
parents: 2267
diff changeset
    16
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.
2189
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
    17
b2f75d4bf715 Add LuaRules.wiki
Wuzzy <almikes@aol.com>
parents:
diff changeset
    18
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.