Page 1 of 1

How can I debug love?

Posted: Wed Jun 24, 2015 7:47 am
by lovefirstly
As a new lover, I wirte love code like this:

1. Write a lua file
2. Zip it to xxx.zip
3.Rename it to xxx.love
4.If I have error in it, love's window will show it. Then I have to go back to the first step to modify the lua file, It's too much trouble.

So I want to know if there is a solution to debug love which let me know the error earlier.

Re: How can I debug love?

Posted: Wed Jun 24, 2015 8:23 am
by ivan
2 and 3 can be combined by dragging your game folder onto 'love2d.exe'

There is the 'strict.lua' library (don't think it's a part of Love2D) that raises an error when you use unreferenced global variables.
But in general debugging Lua is not the same as with static languages.

PS. There are probably better debug tools out there, I'd be curious to see what people use.

Re: How can I debug love?

Posted: Wed Jun 24, 2015 9:05 am
by lovefirstly
ivan wrote:2 and 3 can be combined by dragging your game folder onto 'love2d.exe'

There is the 'strict.lua' library (don't think it's a part of Love2D) that raises an error when you use unreferenced global variables.
But in general debugging Lua is not the same as with static languages.

PS. There are probably better debug tools out there, I'd be curious to see what people use.
Thanks your answer. You said "2 and 3 can be combined by dragging your game folder onto 'love2d.exe". It's means I can drag the xxx.zip onto love2d. But I tried, nothing happen when I drag onto love;'s window.I use XP system and love 0.9.2, it's a problem?

Re: How can I debug love?

Posted: Wed Jun 24, 2015 9:12 am
by zorg
I have a .bat file in love's directory with the line

Code: Select all

love.exe projectfolder
where projectfolder is where a project's main.lua is. I created said .bat file with notepad.
Doubleclicking that will run the game.
For ease of access, i also create a link to it that's on my desktop, so i dont have to navigate through folders.

What this means is that you really dont need to zip/rename it all the time while you're developing the thing. That can be done after you deem your thing finished or at least releaseable.

A few other options:
- Use an IDE like zerobrane studio
- A bit more questionable and slightly harder route would be to use a library that allows code hotswapping, but those have their own disadvantages as well as advantages.
- The hardest would be to create your own hotswapping solution, meaning you get instant feedback on your code changes while it runs

At least, that's my take on things; after trying out these, i decided to just code in sublime text (2), but that fits my own train of thought :3

Edit: edited for clarity

Re: How can I debug love?

Posted: Wed Jun 24, 2015 7:50 pm
by Jasoco
Don't even bother zipping the project up until you need to share it. It's just a waste of time during development. You can run the .love from Löve as a folder. There's probably .bat files you could make to run it for you easily. Zipping is a finalization method and isn't required until the time comes. Say you want to share it on the forum or with a friend.

On Windows you'd need to enable the console using its flag in the conf.lua file. That will let you print() stuff out to help debug.

Otherwise you can write GUI based in-game debugging tools as well. It's what I do. I write my own performance graph. Or I'll draw shapes to the screen representing collision boxes. Stuff like that.

Re: How can I debug love?

Posted: Wed Jun 24, 2015 7:57 pm
by Nixola
Jasoco wrote:On Windows you'd need to enable the console using its flag in the conf.lua file. That will let you print() stuff out to help debug.
Unless you're using sh/bash in cygwin (my experience) or something that handles stdout correctly (my supposition); setting it to true in that case will prevent you from getting any output in a console.

Re: How can I debug love?

Posted: Thu Jun 25, 2015 8:37 am
by lovefirstly
zorg wrote:I have a .bat file in love's directory
Thanks, Save me a lot of time. :awesome:

write a bat file like this: love.exe %cd%

Re: How can I debug love?

Posted: Sun Jun 28, 2015 8:26 pm
by Kotoromo
Also, all of your steps could be easily avoided.

If you're using Notepad++, you can follow these instructions:

https://love2d.org/wiki/Notepad%2B%2B

If you're using SublimeText2 or 3, then I suggest you get PackageInstaller plug-in and then search for Lua Love or SublimeLove on PackageControl's Install Package.