tw.debugger
Side: Shared + Client
Performance benchmarking and visual debugging tools.
Shared Functions
tw.debugger.benchmark(label?, cb)
Measures the execution time of a function.
| Parameter | Type | Default | Description |
|---|---|---|---|
label | string? | nil | Optional label printed with the result |
cb | function | — | Function to benchmark |
Returns: number (execution time in microseconds)
tw.debugger.benchmark_repeat(label?, iterations?, cb, delay_between?)
Runs a function multiple times and returns the average execution time.
| Parameter | Type | Default | Description |
|---|---|---|---|
label | string? | nil | Optional label printed with the result |
iterations | integer? | 1000 | Number of iterations |
cb | function | — | Function to benchmark |
delay_between | integer? | nil | Milliseconds to wait between iterations |
Returns: number (average execution time in microseconds)
Client Functions
tw.debugger.resetText()
Resets the Y offset for drawText. Call at the beginning of each frame to stack text lines from the top.
tw.debugger.drawText(text, pos_x?, pos_y?)
Draws debug text on screen. Each call advances the Y position automatically if pos_y is not specified.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | string | — | Text to display |
pos_x | number? | 0.5 | Screen X position (0.0 to 1.0) |
pos_y | number? | auto | Screen Y position (auto-increments if omitted) |
tw.debugger.drawSphere(coords, radius?, color?)
Draws a 3D debug sphere in the world.
| Parameter | Type | Default | Description |
|---|---|---|---|
coords | vector3 | — | World position |
radius | number? | 0.5 | Sphere radius |
color | table? | {r=255, g=0, b=0, a=128} | RGBA color |
Examples
Benchmark a function
lua
local time = tw.debugger.benchmark("hash lookup", function()
local hash = GetHashKey("a_m_m_rancher_01")
end)
print("Took " .. time .. " us")Average benchmark over many iterations
lua
local avg = tw.debugger.benchmark_repeat("inventory check", 5000, function()
tw.fw:canUseItem(source, "bandage", 1)
end)
print("Average: " .. avg .. " us")On-screen debug text (client)
lua
-- In a tick loop
CreateThread(function()
while true do
Wait(0)
tw.debugger.resetText()
tw.debugger.drawText("Player Pos: " .. tostring(GetEntityCoords(PlayerPedId())))
tw.debugger.drawText("Health: " .. GetEntityHealth(PlayerPedId()))
tw.debugger.drawText("Speed: " .. GetEntitySpeed(PlayerPedId()))
end
end)3D debug sphere
lua
-- Visualize a collection point
tw.debugger.drawSphere(vec3(-301.62, 783.04, 117.75), 1.0, { r = 0, g = 255, b = 0, a = 100 })Notes
- Benchmark results are in microseconds (1 ms = 1000 us).
drawTextauto-increments the Y position with each call. UseresetText()at the start of each frame to avoid text drifting down.drawSpheremust be called every frame to remain visible (like all draw functions in RedM).- These tools are intended for development only. Remove debug draws before shipping.

