Debug Console

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
User avatar
Outlaw11A
Prole
Posts: 4
Joined: Tue Mar 19, 2013 9:18 am

Debug Console

Post 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
LEGENDCRAFT MINECRAFT SERVER: play.legendcraft.beastnode.net
http://legendcraft.beastnode.net/
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Debug Console

Post 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
Last edited by Zer0 on Sun Mar 24, 2013 5:07 pm, edited 1 time in total.
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: Debug Console

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

Re: Debug Console

Post by bartbes »

I can't help but feel Zer0 is trying to recreate repler.
User avatar
Outlaw11A
Prole
Posts: 4
Joined: Tue Mar 19, 2013 9:18 am

Re: Debug Console

Post by Outlaw11A »

WOW! Thanks for the help guys! Will defs look into this.
LEGENDCRAFT MINECRAFT SERVER: play.legendcraft.beastnode.net
http://legendcraft.beastnode.net/
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 70 guests