While breakpoints can be set on any file and can even have conditions I’ve been trying to figure out how I can conditionally break by issuing a command in the code. I hit upon an easy method.
I create a function with a condition that works like an assertion. The idea is the code will break when the condition is False. In Studio I set a breakpoint on the indicated line. Whenever this function is called the breakpoint will fire. Step Out will then allow debugging the context.
function breakpoint(condition, comment)
if condition then return end
--
-- Set breakpoint here
-- Use Step Out to continue
--
end
This function can then be called within some code that needs debugging.
function problem()
if condition then
breakpoint() -- Trigger breakpoint for debugging
... problem code ...
end
end
Common Module
What I’ve done is placed this in the module that contains utility functions. I require this module in almost every script I create so I only need to set the breakpoint once and then any script in the game can trigger it programatically.
-- Breakpoint module
local module = {}
function module.breakpoint(condition, comment)
if condition then return end
--
-- Set breakpoint here
-- Use Step Out to continue
--
end
return module
Calling it looks like this.
local utility = require(path.to.utility)
-- Trigger breakpoint
utility.breakpoint()