Page 1 of 1
love.mouse not returning a number
Posted: Wed Nov 02, 2011 2:42 am
by seven
Hello world. I'm a novice programmer, but I've learned a lot using this framework. I've run into a bit of a problem, though:
Code: Select all
function love.update()
mousex, mousey = love.mouse.getPosition()
if love.mouse.isDown("r") then
love.graphics.print(mousex)
end
end
The code is supposed to assign the mouse's x position to the variable mousex, and print its value when the RMB is held. It returns an error when I right-click: graphics.lua:1: bad argument #2 to 'print1'
(number expected, got no value)
what do?
Re: love.mouse not returning a number
Posted: Wed Nov 02, 2011 2:58 am
by TechnoCat
seven wrote:Hello world. I'm a novice programmer, but I've learned a lot using this framework. I've run into a bit of a problem, though:
Code: Select all
function love.update()
mousex, mousey = love.mouse.getPosition()
if love.mouse.isDown("r") then
love.graphics.print(mousex)
end
end
The code is supposed to assign the mouse's x position to the variable mousex, and print its value when the RMB is held. It returns an error when I right-click: graphics.lua:1: bad argument #2 to 'print1'
(number expected, got no value)
what do?
1. Don't draw in love.update(), even if your function call was correct, it won't print it if you do the
love.graphics.print in update. Unless you meant print(), which goes to console. print() works anywhere AFTER LOVE.LOAD() IS CALLED.
2.
love.graphics.print takes at least 3 arguments: string, x, y.
Re: love.mouse not returning a number
Posted: Wed Nov 02, 2011 3:00 am
by Taehl
Your error is simple: You're not allowed to use drawing functions anywhere except in love.draw(). After that, you can't forget to have coordinates for your printed text (they're the two parameters after the text you want to show).
EDIT) TechnoCat beat me to it. XP