Using the Lua Debugger

Using the Lua Debugger

10 min


The built-in debugger offers utilities commonly found in an IDE (Integrated Development Environment). It is enabled by default but can be toggled on or off through the Studio Settings menu.

Using Breakpoints

Breakpoints are “checkpoints” within a script. If a breakpoint is set for a line of code, the script will pause when it tries to execute that line. To set a breakpoint within a script, click in the gutter between the line number and its code. This will create a red dot indicating a breakpoint.

When a script is paused at a breakpoint, you can continue executing the script line by line. This lets you closely monitor how variables are changed and which functions are called. There are three ways to step through code, all available from in the Script Menu tab.

Button Action Description
Step Into The Step Into button moves the debugger into the function on the current line. If there is no function on the current line, the debugger will move to the next line.
Step Over The Step Over button moves the debugger to the next line of code, not moving into functions.
Step Out The Step Out button moves the debugger out of the current function and to the next line of code after the function was initially called. If the current line is not inside a function, this button will move to the next line.

Watching Variables

You can also tell the debugger to “watch” variables, keeping track of their value when you hit breakpoints. To add a variable to the watch list:

  1. Click the Add Watch button from the Script Menu tab.
  2. In the prompt window that opens, type in the variable’s name and confirm.
  3. From the Watch window that opens — also accessible through ViewWatch you can monitor the variable’s value as you step through breakpoints.

Call Stack

The Call Stack window tells you exactly where code execution is when paused or at a breakpoint.

  1. Open the Call Stack window from the View tab.
  2. Step through breakpoints and notice how the stack reflects the order of operations. If the current breakpoint is inside a function, the following item in the stack shows the line where the function was called.
  • debugging
  • bugs
  • tools