How to Debug LOVE Program?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
jtianling
Prole
Posts: 5
Joined: Sat Jan 30, 2010 5:19 am

How to Debug LOVE Program?

Post 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?
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: How to Debug LOVE Program?

Post 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)
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
jtianling
Prole
Posts: 5
Joined: Sat Jan 30, 2010 5:19 am

Re: How to Debug LOVE Program?

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How to Debug LOVE Program?

Post 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.
jtianling
Prole
Posts: 5
Joined: Sat Jan 30, 2010 5:19 am

Re: How to Debug LOVE Program?

Post 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.
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 Program?

Post 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.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to Debug LOVE Program?

Post 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.
Help us help you: attach a .love.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: How to Debug LOVE Program?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to Debug LOVE Program?

Post by Robin »

DLLs, eh? How about SOs?
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How to Debug LOVE Program?

Post by bartbes »

One word: automake.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 2 guests