Flavor Text: Debuggin’ a Plugin
Meet Doug.
Doug is chuggin’ on writing a Plugin. Chug Chug.
Doug has a bug in Doug’s Plugin. Ugh!
Doug enables Plugin Debugging in Beta Features, then sets Plugin Debugging Enabled in Settings. Will it help? He is not sure. shrug.
Doug’s local plugins are now visible under PluginDebugService in Explorer. He can browse source, set breakpoints, watch variables, and examine the callstack like a debugging thug. He can also tweak the code and Save And Reload the plugin to immediately see if his changes fixed the bug.
Doug’s pulled the plug on his plugin bug! Hugs! Now he can get back to drinking from his mug (chug chug) and eating his favorite snack (spicy nuggs).
The Business
Making Plugins is hard! Plugins are extensions of native Studio functionality and work a bit differently than building a game. To make this process easier, Studio now offers the ability to point the Lua debugger at executing Plugin scripts. The debugger is a powerful tool that can quickly hone in on issues, allowing you to fix them with minimum weeping and gnashing of teeth.
Enabling the Plugin Debugger
Beta Feature
The Plugin Debugger is currently supported as a Beta Feature.
To enable: File → Beta Features → Plugin Debugging.
You will have to restart Studio.
Settings
Once the Beta Feature is enabled, you have to enable some Settings (since the plugin debugger adds items to the Explorer, and Plugin Debugging is not a common workflow).
To enable: File → Settings → <Search on “Debug”>
Set “Plugin Debugging Enabled” and “Lua Debugger Enabled” to true.
You will have to restart Studio again (I know… sorry…)
Plugin Debug Workflow
Create a Local Plugin
Save the Plugin you wish to debug as a local plugin. (The plugin debugger only works on local plugins: not built-in, and not plugins installed from the web).
Debug
In the Explorer window you should see a “PluginDebugService”. Open this to see all of your local plugins.
Note that you are seeing a representation of each plugin as it exists and executes in Studio: these plugins are actively running as you browse them.
You can navigate the contents of the plugins to see and edit the scripts in the plugin, and to set breakpoints.
Once a breakpoint is hit, you can navigate the call stack, add watches to inspect the value of variables, step in/out/over functions, etc.
For more background on using the Lua debugger, see here.
Edit and Reload
You can edit the scripts under the Plugin Debug Service to fix problems as you find them. To test your changes, right click on the Plugin under the Plugin Debug Service and select “Save and Reload Plugin”. This will write your plugin back out to the local plugins directory, unload the old version of the plugin, and reload and execute the new updated plugin.
Warning: If your plugin modifies itself (say by moving scripts around or adding new scripts as it runs), Save and Reload Plugin will cause problems: you are saving out the plugin as it currently exists in memory: you are not saving out the “pristine” version as it was originally loaded.
Thanks
This would not be possible without the tireless efforts of @CycloneUprising, @MetalMax2, @IcyTides, @ResetVector and @sunny0724
Happy debugging!