HomeIndex

Debug Functions

trace(state)
Turns on or off the tracing of source code.
startglobalthread/startthread([this_table, ]function, [param, ... ])
Starts a new thread using function and passing the params
startthread returns a unique thread id that can be used to monitor or kill the thread.
startthread(watchLight, Office.light) tid = startthread(controlBear) stopthread(tid)
Note that when starting a thread, you pass the name of the function and don't call the function.
startthread(watchLight(), Office.light)
This will call the function on the current thread and then probably throw an error.
If this_table is passed, it becomes the this for the function. This is needed for when threads are started from detached functions that need to be part of a table.
If the startthread(...) form is used, the thread will be killed when leaving the current room
stopthread(thread_id)
Stops a thread based on a unique thread id.
tid = startthread(controlBear) stopthread(tid)
threadrunning(thread_id)
Returns true if the thread is running.
tid = startthread(controlBear) if (threadrunning(tid)) { print("running") } else { print("stopped") }
threadid()
Returns the unique thread id of the currently running thread.
threadpause(thread_id, state)
Pauses or unpauses a thread based on 'state'.
threadpause(watch_tid, true)
threadpauseglobal(state)
Pauses or unpauses all global threads
threadpauseglobal(true)
Also returns the number of threads acted upon.
threadpausable(thread_id, state)
Marks a thread as pausable to unpausebale based on state
This is mainly used so when a cutscene pauses threads, some can be immune.
breakhere(frames=1)
Breaks (or yelds) a thread until the next frame.
breakhere() // Breaks for 1 frame breakhere(5) // Breaks for 5 frames.
Only threads started with startthread() can have break commands, otherwise an error is thrown.
breaktime(duration) | breaktime(from,to)
Breaks (or yelds) a thread for duration seconds.
breaktime(10.0) // Breaks for 10 seconds breaktime(2.0,5.0) // Breaks randomly for `2.0` to `5.0` seconds.
Doing a breaktime(0.0) will cause the thread to break for 1 frame.
breakwhilerunning(thread_id)
Breaks while the thread with thread_id is running.
breakwhilerunning(bear_attacks_tid) print("I think I'm dead")
loglevel(level)
Sets the current logging output level.
printlog(level, value, [value, ...])
Prints to the debug console at a log level of level
If the loglevel() is below level then nothing will print.
addconsolebutton(color, title, command)
Adds a button to the debug console to execute a command when pressed
addconsolebutton(0x00FF00, "Player", "watch player") addconsolebutton(0xFF0000, "Trace", "trace") addconsolebutton(0x0040FF, "Threads", "show threads")
watchvar(var)
Opens up a debug window that live-watches the variable allowing values to be changed.
dumpstack()
Dumps the call stack to the debug console
This also happens when an error is thrown.
dumpvar()
Dumps a variable to the debug console