Debugging
CompilesWhen a script doesn’t do what you expect, don’t guess: make it tell you.
Print a value
Section titled “Print a value”let me: Entity = $entity.get()$debug.print_line("created on {}", [$entity.get_name(me)], false)Each {} is filled with the next value in the list. Anything can go in: numbers, text, vectors, handles.
Tag your messages
Section titled “Tag your messages”The log is busy. Start every message with your script’s name in brackets, so you can find yours:
$debug.print_line("[welcome_mat] greeted {} so far", [3], false)Warnings and errors
Section titled “Warnings and errors”Use the level that matches: print_line for tracing, print_warning when something’s off but the script can carry
on, print_error when it can’t.
let name: string = "partner_pad"let target: Entity = $entity.get_child_named(name, true, $entity.get())if !target { $debug.print_warning("[teleport_pad] no entity named {}", [name], false) return}Printing a warning where a lookup fails, and then returning, turns a silent “nothing happens” into a message that says exactly what’s missing.
Which machine said it?
Section titled “Which machine said it?”Your script runs on the server and on every client, so each message may appear several times. Say which copy it came from:
let side: string = if $net.is_server() { "server" } else { "client" }$debug.print_line("[press_counter] {} sees count {}", [side, 4], false)Is the event even running?
Section titled “Is the event even running?”Put a print as the first line of the event. No message means the engine never called it. Check the spelling of the
event’s name, that it’s event export fn, and that the component is on an entity the game loads.
event export fn trigger_overlapped(other, unused) { $debug.print_line("[my_script] overlap from {}", [other], false)}When the compiler complains
Section titled “When the compiler complains”Every compiler message has an id like V0302. Look it up in Compiler messages for
what it means and how to fix it.