I’m currently Debugging a bug that I can’t find where it’s coming from. And I’m wondering what you guys do when you debug scripts? Is there some formate you use to help identify the problem?
Just use print in places to see if the code there runs or not.
if condition then
print("ran") --if this runs, then this prints. you can debug that way
--if it doesn't print, then I know that condition is nil or false, so i can check it that way
This is useful for when you don’t know where the bug is. Whenever the print doesn’t print and you want it to, you’ve found the bug.
Probably not the best way, but I just add
print()s everywhere and check the value of every variable, and if there’s a discrepancy I look into it.
Yeah I know, but i cant post there because im not a “Regular”
There are many utilities that you can use to debug your own scripts. The idea is that you want to isolate the bug down to a specific location, or if you know, then try to rat out what’s causing it.
Prints are a common way to get things done. Although tedious if not already being fed into a debugging framework of sorts, they’re trivial to throw around in your code. You can check up to which prints run and which don’t, then figure out the problem there. You can also print the values of necessary variables.
The View tab in your ribbon bar also has a few options for debugging, be it for performance or for errors. A few of those widgets are dedicated to the Lua Debugger which may help you. For example, breakpoints will pause code at specific lines without needing to edit it so that you can inspect what’s occurring when that line is running.
This article has useful information worth reading up on:
The current category is fine. There’s no need to bring this to #discussion because there aren’t really many ways to efficiently debug code and I wouldn’t say this is much of an open question.