User Tools

Site Tools

Urban Games

modding:syntax

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
modding:syntax [2020/06/11 01:26]
yoshi [Imports]
modding:syntax [2020/08/01 12:35]
yoshi [Loops]
Line 10: Line 10:
 ===== Basic Syntax ===== ===== Basic Syntax =====
  
-The most common syntax structures used for Transport Fever 2 are described briefly below. A full reference of the LUA syntax is available at the [[https://www.lua.org/manual/5.3/|website of LUA]].+The most common syntax structures used for Transport Fever 2 are described briefly below. A full reference of the LUA syntax is available at the [[https://www.lua.org/manual/5.2/|website of LUA]].
  
 ==== Functions ==== ==== Functions ====
Line 17: Line 17:
  
 <code lua> <code lua>
-function functionname(parametername1, parametername2)+local function functionname(parametername1, parametername2)
   -- code   -- code
   return resultname   return resultname
Line 105: Line 105:
 The index starts with the startvalue and is modified by stepwidth every time it finishes a loop run. if stepwidth is omitted, the step is 1. As soon as the index is greater or equal to the endvalue, no new loop runs are started. The index starts with the startvalue and is modified by stepwidth every time it finishes a loop run. if stepwidth is omitted, the step is 1. As soon as the index is greater or equal to the endvalue, no new loop runs are started.
  
 +To iterate over all key-value pairs in a table, it is possible to use the ''pairs'' function:
 +
 +<code lua>
 +for k,v in pairs(t) do 
 +  -- looped code
 +end
 +</code>
 +
 +In the looped code, the key can be used with ''k'' and the value can be used with ''v''.
 ==== Conditionals ==== ==== Conditionals ====
  
modding/syntax.txt · Last modified: 2020/09/02 23:27 by yoshi