Breakpoints are checkpoints that pause or “break” the execution of your scripts at specific lines. You can use the pauses to inspect and debug your experience, watch variables, and inspect the call stack. Breakpoints are one of the most effective ways to debug functions, and therefore one of the most important debugging tools.
You can configure breakpoints to break only if certain conditions are met, to print a message to the Output window, and to run only on the client or server. You can also mix these configurations together to best suit your debugging needs.
Standard breakpoints pause your scripts when you playtest. To insert a standard breakpoint at a line of code, click the margin to the right of its line number. The breakpoint appears as a red dot.
If you insert a breakpoint at a line in a script, the script pauses before it executes that line. A yellow arrow called the “debugger” indicates which line of code executes next.
When the script pauses, you can monitor how your experience changes as the current line executes. You can also execute the following code one line at a time by stepping through them with the buttons in the Script Menu tab. The following table summarizes the three ways to step through code.
To remove the debugger and continue executing your code, click Resume in the Script Menu tab.
|Step Into||The Step Into button moves the debugger into the code of the function on the current line. If there is no function on the current line, the debugger moves 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 call. If the current line isn't inside a function, the debugger moves to the next line.|
Logpoints are breakpoints that log messages to the Output window without pausing your scripts. This is useful for debugging variable values. Logpoints print the values for the variables before the line executes.
Logpoints can be more efficient for debugging variables than
print() statements because they allow you to log messages to the Output window without having to stop or restart the active play session. They can help you keep your code clean while debugging and are easier to remove when you finish debugging.
You can convert existing breakpoints to be Logpoints by editing them to enable Continue Execution and have Log Messages.
Conditional Breakpoints are breakpoints that pause your script only if a condition is true. This is useful when you want to debug how your functions execute only if certain variables have certain values.
You can convert existing breakpoints to be Conditional Breakpoints by editing them to disable Continue Execution and have Conditions.
Standard breakpoints pause both the client and server. If you want to create a breakpoint that pauses on only the client or server, you can create Contextual Breakpoints while testing your experience. This is useful for debugging a ModuleScript that you reuse in both LocalScripts and Scripts.
Contextual Breakpoints are available only while testing. For more information on different testing modes, see Testing Modes.
You can insert, edit, disable, and delete standard breakpoints, Conditional Breakpoints, Contextual Breakpoints, and Logpoints by following similar steps.
The icon for each breakpoint indicates its type:
- A red circle indicates a standard Breakpoint.
- A red circle with an equal sign indicates a Conditional Breakpoint.
- A red diamond indicates a Logpoint.
- A yellow circle indicates a Contextual Breakpoint.
You can insert a breakpoint at any line of executable code.
To insert a standard breakpoint at a line of code, left-click the margin to the right of its line number. You can also right-click the margin and click Insert Breakpoint. The breakpoint appears as a red dot.
To insert a Conditional Breakpoint or Logpoint at a line:
- Right-click the margin to the right of the line number.
- Click Insert Conditional Breakpoint… or Insert Logpoint… to display the Edit Breakpoint pop-up.
- Define the Condition if applicable.
- Define the Log Message if applicable.
- Click Save.
To insert a Contextual Breakpoint at a line, you must first insert and delete a standard breakpoint:
- Left-click the margin to the right of the line number to insert a standard breakpoint. Left-click the breakpoint to delete it.
- Right-click the margin to the right of the line number to open the insertion menu.
- Click Insert Contextual Breakpoint.
Contextual Breakpoints are available only while testing. If you don’t see the option to insert a Contextual Breakpoint, insert a standard breakpoint, then check that your script has a blue client symbol or green server symbol.
Breakpoints have three options: Condition, Log Message, and Continue Execution.
The Condition is the expression that determines whether the breakpoint activates. The Condition is optional. If the Condition is empty, the breakpoint always activates. For example, if you want the breakpoint to activate only if the variable
42, then define the Condition to be
n == 42.
The Log Message is the expression that prints to the Output window when the condition is true. The Log Message is the same as what you would put as the argument for a
print() statement. For example, you can define the Log Message to be
"The value of n:", n to print the same message as
print("The value of n:", n).
The Continue Execution option determines whether the breakpoint pauses the script if it activates. This option is enabled by default for Logpoints but disabled for other types of breakpoints.
To edit the options for a breakpoint:
- Right-click the breakpoint.
- Click Edit Breakpoint to open the Edit Breakpoint pop-up.
- Adjust the options for the breakpoint to meet your debugging needs.
To disable or enable a breakpoint, toggle the Enabled checkbox in the Edit Breakpoint pop-up. You can also right-click the breakpoint icon and click Disable Breakpoint or Enable Breakpoint.
To delete a breakpoint, left-click its icon. You can also right-click its icon and click Delete Breakpoint.
Using the Breakpoints Window
The Breakpoints window has buttons to enable, disable, and delete some or all breakpoints.
To open the Breakpoints window:
- Click the View tab at the top of Studio.
- Click Breakpoints.
You can enable and disable breakpoints by clicking the checkbox in the Enabled column.
|Delete the selected breakpoint.|
|Delete all breakpoints.|
|Disable all breakpoints. If all breakpoints are disabled, enable them all.|
|Go to the source code for the selected breakpoint.|