Monocle - Love2D debugging for 0.9.0
Posted: Sun Jan 26, 2014 2:01 am
Hey Lövers. I've been looking through the various debug libraries that the Love2D community has to offer, of which some of them are great, some are okay, and some don't even work anymore in version 0.9.0. I couldn't quite find what I was looking for, though, so I decided to create my own library. I present, Monocle. Because monocles are awesome. I took some of the ideas from the libraries that were currently out there (lick, donut, etc) and put them together. With Monocle, you can watch variables as you play. In addition, you optionally edit the game, and Monocle will watch files and reload ‘main.lua’ automatically when it spots something has changed.
v0.2.0
Current Features
Implementation:
And that’s it. Let’s say we want to watch the current FPS of the game. We just need to add this line somewhere in our code:
And voilà, when you press the debug button (by default it’s the “~” key, but you can set it yourself), the watched variable will show up in the corner, along with the name you gave it!
Oh, you can watch string and number variables too (tables soon). so if you have a variable player.health that you really want to watch,
is perfectly valid.
The best part? Even if there's an error, the values of your expressions at the time of the error still show up.
Also, you can pass in certain parameters when you load Monocle. Here's a list of them, with their default values:
Here's the repository, for all you GitHub fans.
https://github.com/kurtjarvi/monocle
I hope y'all enjoy
v0.2.0
Current Features
- Can watch variables and complex expressions
- Can watch files and reload them when they change
- Custom error handler that will display the values of all of your watched variables in the error screen
- Reloads the game after any files have been changed, even after an error has occured
- Custom colors
- In-game console for debugging purposes
- Ability to use the aforementioned in-game console *even* AFTER the game has crashed
Implementation:
Code: Select all
require ‘monocle’
Monocle.new({})
function love.update(dt)
Monocle.update()
end
function love.draw()
Monocle.draw()
end
function love.textinput(t)
Monocle.textinput(t)
end
function love.keypressed(text)
Monocle.keypressed(text)
end
Code: Select all
Monocle.watch("FPS", function() return math.floor(1/love.timer.getDelta()) end)
And voilà, when you press the debug button (by default it’s the “~” key, but you can set it yourself), the watched variable will show up in the corner, along with the name you gave it!
Oh, you can watch string and number variables too (tables soon). so if you have a variable player.health that you really want to watch,
Code: Select all
Monocle.watch("health", function() return player.health end)
The best part? Even if there's an error, the values of your expressions at the time of the error still show up.
Also, you can pass in certain parameters when you load Monocle. Here's a list of them, with their default values:
Code: Select all
Monocle.new({ -- ALL of these parameters are optional!
isActive=true, -- Whether the debugger is initially active
customPrinter=false, -- Whether Monocle prints status messages to the output
printColor = {51,51,51},-- Color to print with
debugToggle='`', -- The keyboard button for toggling Monocle
filesToWatch= -- Files that, when edited, cause the game to reload automatically
{
'main.lua'
}
})
https://github.com/kurtjarvi/monocle
I hope y'all enjoy