Page 1 of 1
Debug Console
Posted: Sun Mar 24, 2013 3:27 am
by Outlaw11A
Hey Guys!
I was wondering if someone could help me out with the debug console that can be opened if it is true in the conf.lua file.
Am I able to view variable values in it? Could I change the variables from the console, then have them change the game?
How would I go about doing this?
Any help would be great.
Thanks
Outlaw11A
Re: Debug Console
Posted: Sun Mar 24, 2013 4:41 pm
by Zer0
you could view the variable in it with (ex: love.graphics.getMode() whould return screen size and such) and then set the variable again with (love.graphics.setMode(width,height,...)
as for input in the command prompt I would suggest a second thread so the game doesn't freeze when it's looking for input in the console window.
SCRATCH THIS
Code: Select all
-- EXAMPLE THREAD SET THING
require "love.event" -- Makes sure it has access to love.event functionality as only love.thread is loaded in a new thread by default
local function cmd(s)
local foundSpaceAt = string.find(s, " ") -- Looks for a space
s = string.sub(s,1,foundSpaceAt)-- Take the first command out of the string
return string.lower(s) -- Would make qUiT quals to quit
end
repeat
local command = io.read()
if cmd(command) == "quit" then
love.event.push('q') -- Quits the game
end
until false
I read a little about how you should NOT use love.graphics while in a thread so I came up with a different idea
Code: Select all
--main.lua
local cmd = love.thread.newThread("commandThread","commands.lua") -- unsure if .lua need to be included
function love.load()
cmd:start()
end
function love.update(dt)
local command = cmd:get("command") -- Gets command from the thread
if command then -- It's nil if no new commands has appeared
if string.sub(command,1,4) == "quit" then -- the 4 is because there's 4 letters in quit
love.event.push('q') -- QUITS
end
end
end
Code: Select all
--commands.lua
repeat
local cmd = love.thread.getThread("commandThread") -- Gets the current thread
local command = io.read() -- Reads the user input
if command then cmd:set("command",command) end -- Sets the variable to be used in the main thread
until false
hope this helps
Re: Debug Console
Posted: Sun Mar 24, 2013 4:55 pm
by Qcode
You can do something like this
Code: Select all
function love.keypressed(key)
if key == "rctrl" then
debug.debug()
end
end
That will freeze your game, and you can now interact with the console. You can change variables, and inspect local variables (there's info on how to do this here
http://pgl.yoyo.org/luai/i/debug.debug). To continue playing the game, enter just "cont".
Re: Debug Console
Posted: Sun Mar 24, 2013 8:38 pm
by bartbes
I can't help but feel Zer0 is trying to recreate
repler.
Re: Debug Console
Posted: Mon Mar 25, 2013 10:10 pm
by Outlaw11A
WOW! Thanks for the help guys! Will defs look into this.