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
modding:syntax [2020/08/01 12:32]
yoshi
modding:syntax [2020/09/02 23:27] (current)
yoshi [Loops]
Line 98: Line 98:
  
 <code lua> <code lua>
-for i = startvalue, endvalue, stepwidth+for i = startvalue, endvalue, stepwidth do
   -- looped code   -- looped code
 end end
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.1596277950.txt.gz · Last modified: 2020/08/01 12:32 by yoshi