love.mouse not returning a number

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
seven
Prole
Posts: 1
Joined: Tue May 31, 2011 7:18 am

love.mouse not returning a number

Post 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?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: love.mouse not returning a number

Post 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.
Last edited by TechnoCat on Wed Nov 02, 2011 3:03 am, edited 6 times in total.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: love.mouse not returning a number

Post 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
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Post Reply

Who is online

Users browsing this forum: Google [Bot], MummyTheTiger, Semrush [Bot] and 4 guests