Page 1 of 1

How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 5:26 am
by jtianling
That so Happy to program with LOVE, but when the program is bigger and bigger,How we can control the bug?I mean Debug the LOVE program.As I know,LUA don't have a good debug program,SciTE's debug function is not so good as gdb or VS.But It can be used.But how to Debug LOVE Program?

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 5:33 am
by Taehl
Depends on what, exactly, you want to debug. Myself, I generally like throwing debug messages on the screen, so I can watch my variables in-game. For instance, right now I have:

Code: Select all

-- Print debug data
love.graphics.print("tiles: "..tilecount(), 12, 12)
love.graphics.print("bgtiles: "..bgtilecount(), 12, 26)
love.graphics.print("fps: "..love.timer.getFPS(), screen.x-62, 12)
love.graphics.print("tiles carried: "..player.tiles.."/16", screen.x-115, 26)

message = "Player's arms touch: "
if not player.armstouch then message = message.."No"
else message = message..math.round(player.armstouch.x)..", "..math.round(player.armstouch.y)
end
message = message.."\nPlayer's legs touch: "
if not player.legstouch then message = message.."No"
else message = message..math.round(player.legstouch.x)..", "..math.round(player.legstouch.y)
end
message = message.."\nPlayer's action: "..player.action.." "..player.direction
love.graphics.print(message, 60, screen.y-101)

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 7:25 am
by jtianling
Is that means if you want to know which the branch the program goes,you should add log print out in every branch(every if ?)That's so inconvenience.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 10:09 am
by bartbes
branches?
And it normally helps if you just add a debug print statement for some important lines, then at least you know where to add extra debugs when something doesn't work out.
And wanted to add that this is a lua problem, really, not a love one.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 11:34 am
by jtianling
That's a easy thing to make a console debug program for lua,because lua have a built-in debug mechanism.But the gui debug program need too much time to make and there is not a good enough one.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 5:53 pm
by kikito
Instead of using a love-related function (such as love.print) I just use the regular lua print function

Code: Select all

print('my debug message')
This will print on the console - which is fine for me (you will get lots of messages if you print on each update() call)

On windows you will have to set up one flag in order to show these messages. On linux it'll work "out of the box", sending the messages to the console. Don't know about the Mac version.

Debugging is the main reason I've switched to the Ubuntu version from windows - it is easier for me.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 6:49 pm
by Robin
What I often find useful is to have a log function:

Code: Select all

function log(...)
    if dbg then print(...)
end
and set dbg = true at the top of main.lua.

When you want to release your game, just remove the first line.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 6:50 pm
by rude
I once had a plan to release a 100% plain Lua library version of LÖVE (e.g. a love.dll loadable in normal Lua scripts). The LÖVE source does support this as of 0.6.0 (LOVE_BUILD_DLL vs LOVE_BUILD_EXE) in theory, but I've never actually tried it. :rofl:

The whole point was to enable people to use existing debugger tools for Lua, like LuaEdit, which has a graphical debugger.

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 6:54 pm
by Robin
DLLs, eh? How about SOs?

Re: How to Debug LOVE Program?

Posted: Sat Jan 30, 2010 6:56 pm
by bartbes
One word: automake.