Skip to content

System structure

⛔️ WARNING!

If you are not familiar with how to use these functions, it is strongly recommended not to use them, as incorrect usage may lead to serious issues!


OS / System functions

These are direct Lua os functions. Use with extreme care.

lua
os.execute(command)     -- Run a system command (dangerous!)
os.time()               -- Current time (seconds since epoch)
os.clock()              -- CPU time used by program
os.date(format, time)   -- Format date/time
os.getenv(varname)      -- Read environment variable
os.remove(path)         -- Delete file
os.rename(old, new)     -- Rename/move file
os.setlocale(locale)    -- Change locale
os.exit(code)           -- Terminate process

Timers

GrowSoft adds a safe timer system so you don’t need to manage your own loops.

timer.setTimeout

Runs a function once after a delay (in seconds).

lua
local id = timer.setTimeout(2.0, function(player, text)
    print(player:getName() .. " " .. text)
end, some_player, "Hello there")
  • First argument: delay in seconds (2.0).
  • Second: callback function.
  • Remaining arguments: passed into the callback.

timer.setInterval

Runs a function repeatedly every N seconds until cleared.

lua
local id = timer.setInterval(1.0, function()
    print("Tick")
end)

To stop it:

lua
timer.clear(id)

Safe usage pattern (very important)

Bad — capturing full player object inside a delayed timer:

lua
onPlayerDisconnectCallback(function(player)
    timer.setTimeout(5.0, function(my_player)
        print(my_player:getName()) -- Player may no longer exist
    end, player)
end)

Good — store only userID, then re-fetch with getPlayer:

lua
onPlayerDisconnectCallback(function(player)
    local uid = player:getUserID()

    timer.setTimeout(5.0, function(my_player_id)
        local p = getPlayer(my_player_id)
        if p ~= nil then
            print(p:getName())
        end
    end, uid)
end)

If your callback runs after the player disconnects, getPlayer(id) will simply return nil, which is safe.


Text parsing helper

parseText converts key|value lines into a table for easy access.

lua
local data = parseText([[
something|blabla
blabla|something
]])

print(data["something"]) -- "blabla"
print(data["blabla"])    -- "something"

This is especially useful when parsing packed strings from dialogs, HTTP responses, or raw packets.

GTPS Cloud Documentation