Skip to content

Snippets

Small, self-contained pieces. For full worked examples see the game pages under Games.

-- draw ping-free info: the time and the frame the runtime is on
client.set_event_callback("paint", function()
local w, h = client.screen_size()
local hour, minute, second = client.system_time()
local text = string.format("%02d:%02d:%02d | %d fps", hour, minute, second, 0)
local tw, th = renderer.measure_text(nil, text)
renderer.rectangle(w - tw - 22, 14, tw + 8, th + 8, 32, 32, 32, 200)
renderer.text(w - tw - 18, 18, 235, 235, 235, 255, nil, 0, text)
end)
local toggle = ui.new_checkbox("Lua", "Main", "My feature")
ui.set_callback(toggle, function(item)
ui.notify(ui.get(item) and "on" or "off")
end)
local runs = (database.read("runs") or 0) + 1
database.write("runs", runs)
client.log("loaded", runs, "times")
if http then
http.get("https://api.ipify.org?format=json", function(ok, res)
if ok then client.log(json.decode(res.body).ip) end
end)
end
client.delay_call(2.0, function(msg) client.log(msg) end, "two seconds later")