Page 1 of 11

Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 4:55 pm
by kalle2990
Tired of having to restart your whole game when an error occurs or attaching a console, which you have to switch to, just to see your debug printings? Tired of adding extra variable in text to your graphical experience, taking space and looks misplaced? Tired of not having the possibility to execute scripts in-game without attaching a GUI or even writing one yourself? Now all of this is unnecessary!

With the adding of only one script you can now access an in-game console using CTRL+F8 with many lovely features, including:
  • A scrollable list of the output
  • Both errors and printings are sent to the output
  • Only prints the same error once, useful for errors in love.update, can be toggled
  • Semi-transparent console overlay
  • CTRL/Shift + F8 toggle of the console
  • Text input for executing lua snippets right in your console
  • Graphic feedback telling about unseen lines
Debugging Overlay above the NoGame screen
Debugging Overlay above the NoGame screen
debug.png (66.11 KiB) Viewed 27938 times
I'll be continuing to add features such as keyholding and delete key (not to confuse with backspace) functionality for the input field as well as breaking lines which are too long for the screen and a similar feature for the input field. Please give me more ideas of what I could add :)

Note: Require the script outside all love core functions or it will not work.

Code: Select all

--Example
require("debug.lua")

function love.load()
end
Changelog
Version 1.1.5
  • Added Shift + F8 console opening, the old one still remains (Thank you miko)
  • Everything except for settings (which has its own global table) is now put into the local table _Debug (Thank you tentus)
Version 1.1
  • Fixed the console to be hidden at the start
  • Added _OverlayColor to global settings (see _Settings() for a list of settings) Changed location as of 1.1.5 to _DebugSettings.Settings()
Version 1.0
  • Initial version

Re: Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 6:29 pm
by Robin
Nice, seems very useful!

Have you taken a look at other in-game consoles? They might give you ideas for improvement.

Re: Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 6:55 pm
by kalle2990
I have only seen the one in Heroes of Newerth (non-transparent overlay) and in CS (windowed), so I pretty much started from scratch on the interface. There are some features which I feel is rather important, including up/down key tabbing for the recent commands used and maybe some way of adding a dynamic printing to the console using something like Watch(VariableName) instead of having to print the variable every time you wish to check for a change. I felt the transparency was quite important here as one can still interact in the game with the mouse (for more advanced debugging) plus the fact that a solid black background is just too boring in my opinion.

Re: Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 8:42 pm
by BlackBulletIV
Looks good (I haven't played with it yet) :). I'm to add something like this for Grace sometime (I've already got entity and physics outlines), I might take a look at your code to get some inspiration.

Re: Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 11:38 pm
by miko
kalle2990 wrote: [*]CTRL + F8 toggle of the console
BTW, it does not for linux (at least for me) - looks like the window manager hijacks CTRL key, and CTRL+F8 is not passed to the love window. SHIFT+F8 would work.

Re: Debug - A whole new way of debugging your game

Posted: Wed Feb 09, 2011 11:40 pm
by Lap
The ultimate addition would be autocomplete for functions, especially unique ones defined by the running .love file. Not an easy task though.

Re: Debug - A whole new way of debugging your game

Posted: Thu Feb 10, 2011 2:16 am
by tentus
Oh wow, this is cool stuff, I will probably end up using this. Any thoughts about moving everything into a class, so that variables/functions like order and overlay don't conflict with code we've already written?

Re: Debug - A whole new way of debugging your game

Posted: Thu Feb 10, 2011 11:36 am
by Chief
This is the finest sort of awesome! I'll be using it right away! :awesome:

Re: Debug - A whole new way of debugging your game

Posted: Thu Feb 10, 2011 1:00 pm
by vrld
Curiously, recently I have done a similar thing: https://github.com/vrld/love-console (attached .love for convenience). Though it is less suited for debugging but focused on live-coding (or stuff)

Features:
- mimicking the Lua interpreter (multiline input)
- history (press up/down keys)
- tab completion (sort of programmable)
- error catching (i.e. no blue screen)

Re: Debug - A whole new way of debugging your game

Posted: Thu Feb 10, 2011 2:09 pm
by Taehl
Lap wrote:The ultimate addition would be autocomplete for functions, especially unique ones defined by the running .love file. Not an easy task though.
Search _G and every table it has for functions, save their names to a table (on load, not every frame). When typing in commands, sort the table according to how many beginning letters are the same between the table's names and the text. When enter is pressed, loadstring(text)().

That'd be pretty cool.