Code: Select all
function love.keyboard.isDown('p')
love.graphics.print('player.x = ' .. player.x .. '\nplayer.y = ' .. player.y, 0, 0)
end
Code: Select all
function love.update(dt)
Thanks in advance for the help.
Code: Select all
function love.keyboard.isDown('p')
love.graphics.print('player.x = ' .. player.x .. '\nplayer.y = ' .. player.y, 0, 0)
end
Code: Select all
function love.update(dt)
you are mixing up overwriting callbacks and calling functions. You want to call "love.keyboard.isDown('p')", which will return true or false to indicate whether 'p' is pressed, then draw or not draw based on that:NigelNoscopes wrote:I know a sufficient amount of Lua to make things work. I'd like to have an option (similar to Minecraft) where the user can press a key and toggle a print function that prints debug info, such as the x and y coordinates of the player. I tried doing it like this:
This function is under theCode: Select all
function love.keyboard.isDown('p') love.graphics.print('player.x = ' .. player.x .. '\nplayer.y = ' .. player.y, 0, 0) end
block. When I press that key, though, it doesn't print anything. What am I doing wrong?Code: Select all
function love.update(dt)
Thanks in advance for the help.
Code: Select all
function love.draw() -- defining the function "love.draw"
-- draw other stuff
if love.keyboard.isDown('p') then -- call "love.keyboard.isDown" with parameter 'p'
love.graphics.print("debuginfo", 0,0)
end
end
Code: Select all
local debugInfo = false
function love.update(dt)
debugInfo = love.keyboard.isDown('p')
-- the above is the same as:
-- if love.keyboard.isDown('p') then
-- debugInfo = true
-- else
-- debugInfo = false
-- end
end
function love.draw()
if debugInfo then
love.graphics.print('player.x = ' .. player.x .. '\nplayer.y = ' .. player.y, 0, 0)
end
end
This helped me. The above did, as well. Thanks to both of you.Kingdaro wrote:Look at the example on the page for proper usage. Also, all graphics functions have to go under love.draw, not update. This is what you want:I would also recommend reading the PIL, for a better understanding of Lua. If that doesn't help you, look for a more intuitive Lua tutorial that you might understand a little more.Code: Select all
local debugInfo = false function love.update(dt) debugInfo = love.keyboard.isDown('p') -- the above is the same as: -- if love.keyboard.isDown('p') then -- debugInfo = true -- else -- debugInfo = false -- end end function love.draw() if debugInfo then love.graphics.print('player.x = ' .. player.x .. '\nplayer.y = ' .. player.y, 0, 0) end end
EDIT: Didn't even see the post above me. Fuck everything.
Users browsing this forum: No registered users and 6 guests