Page 1 of 1

How to debug LOVE?

Posted: Thu Dec 11, 2014 1:28 am
by vitto
I'm trying to find a way to debug what I code, but the compiler errors blocks my game and I cannot understand what happened exactly, I've tried lovebird with the hope to add more information but it doesn't.

Which are the common ways to debug with LOVE 2D?

Re: How to debug LOVE?

Posted: Thu Dec 11, 2014 1:58 am
by Zilarrezko
Generally just fix the error that it displays, but I'm sure you've already thought of that...

If you have ZeroBrane Studio like I do, you have a built in debugger. By pressing f5 you can run code line by line, or have a breakpoint in your code to so you can press continue in debug mode and it stops at the line of the breakpoint before executing the line. It's been the most helpful thing since metal alloys and plastics (Which I must say are not necessary, but extremely convenient for time and quality).

Other than that, if it's a specific error, and you'd like to put up a .love (or .zip) of your project, we can try to walk you through to the solution attempting to explain every step and ultimately solving your dilemma. Though give a man a fish he eats for a day, teach him to fish, then he can happily debug on his own without having to bog himself down with asking others for help. So I'd prefer to teach you to fish.

Although, unless you mean the game's window literally just exits and no error code is shown, than it's best to post the .love source code so we can work together better.

Re: How to debug LOVE?

Posted: Fri Dec 12, 2014 11:00 am
by undef
I only use print debuging if I can't find the error in the line that was mentioned in the error message.
If there is no error message, but weird behaviour, visualizing things in LÖVE can help as well.

Re: How to debug LOVE?

Posted: Sun Dec 14, 2014 4:16 am
by natev
vitto wrote:I'm trying to find a way to debug what I code, but the compiler errors blocks my game and I cannot understand what happened exactly, I've tried lovebird with the hope to add more information but it doesn't.

Which are the common ways to debug with LOVE 2D?
When I have trouble with compiler errors, I comment out code. If I have to, I comment out the whole module, then half the module, then a quarter of the module... Of course, it takes knowledge of your code to know what other files depend on. Sometimes I comment out bits in other files! So long as I run my scripts frequently, though, it doesn't usually get to that.

I'm trying to put together an in-game console as we speak. Thanks to the way Lua works, it's not that hard to get a textbox that will actually run script that can be put entered at run-time. Script like, "for key, value in pairs(_G) do str = str..key end return str" can be really handy for figuring out wonkiness.

Print debugging is important-- rather than printing to a screen, I write to a log file, which has a lot of advantages: more space for messages (like if I have to do a full-depth dump of _G), I don't get embarrassed if I forget to remove the debug messages, if it parses but still breaks I've still got the error message for more than a microsecond, etc.

I made a getTimeoutFunc() to test some loops (loops that turned out to be fine), and it's in general good practice to create functions that can run concurrently with the main loop-- not necessarily threads, but objects that keep track of how much they've done and where they are in the process and how much time they can afford to waste. Especially for things like AI and resource loading. When you make these, debugging gets easier, because you have breakpoints that you've already coded in.

Re: How to debug LOVE?

Posted: Wed Dec 17, 2014 6:35 pm
by vitto
Thank you all, I got it. I meant especially when I pass data around classes and I need to check if this data is consistent or loss it's format for some reason, basically I have to check it with a hand made console in an overlay on the game.

:monocle:

Re: How to debug LOVE?

Posted: Thu Dec 18, 2014 1:22 am
by Zilarrezko
EDIT: nvm.

Re: How to debug LOVE?

Posted: Thu Dec 18, 2014 12:06 pm
by kikito
You probably know this already, but just incase: if you execute love from a terminal (cd /your/game and then love . - with the dot), any print instruction you do in your game (print('a message'), not love.print(...)) will printed on the terminal - and so will the errors, if they are any.

Because of that last reason, I always execute my games from the console. And I usually just print stuff in the terminal like I said when I need to debug. It has many advangates, for example being able to copy-paste in google. I occasionally use my lib, inspect.lua, to print out complex tables and their members.

If I remember correctly, windows needs an option in the conf.lua file (at least in previous versions of LÖVE) to print stuff in the terminal - Linux and Mac do it by default.

Re: How to debug LOVE?

Posted: Thu Dec 18, 2014 12:15 pm
by Fenrir
If I remember correctly, windows needs an option in the conf.lua file (at least in previous versions of LÖVE) to print stuff in the terminal - Linux and Mac do it by default.
You can for instance call love.exe with the --console option, it'll create a console window with your prints. As kikito mentionned there's also a conf.lua option but I don't remember which one, maybe just t.console = true.