Skip to content

Example script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- dictionaries is a good place to keep stuff clean
local globals = {
    ticks = 0,
    progress = 100
}

-- also dictionaires can work like namespaces
local utils = {
    inc = function(table, key, amount)
        table[key] = table[key] + amount
    end,
    dec = function(table, key, amount)
        table[key] = table[key] - amount
    end,
}

while globals.progress > 0 do
    -- calling function from namespace
    utils.inc(globals, 'ticks', 5)
    utils.dec(globals, 'progress', 1)
end

-- print output to console
print(
    tostring(globals.ticks) -- convert to string first
)