How to debug LOVE?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
vitto
Prole
Posts: 10
Joined: Wed Nov 19, 2014 5:50 pm
Location: Italy
Contact:

How to debug LOVE?

Post 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?
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: How to debug LOVE?

Post 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.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: How to debug LOVE?

Post 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.
twitter | steam | indieDB

Check out quadrant on Steam!
natev
Prole
Posts: 14
Joined: Thu Nov 20, 2014 3:55 pm

Re: How to debug LOVE?

Post 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.
User avatar
vitto
Prole
Posts: 10
Joined: Wed Nov 19, 2014 5:50 pm
Location: Italy
Contact:

Re: How to debug LOVE?

Post 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:
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: How to debug LOVE?

Post by Zilarrezko »

EDIT: nvm.
Last edited by Zilarrezko on Sat Dec 20, 2014 9:19 am, edited 2 times in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How to debug LOVE?

Post 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.
When I write def I mean function.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: How to debug LOVE?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests