[SOLVED]Need help: I want to print x and y position of mouse

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

[SOLVED]Need help: I want to print x and y position of mouse

Post by nice »

Hello boys and girls!

This is a pretty small question but it has been scratching my brain for far too long.
I want to print the X and Y position of the mouse on the Löve/lua screen, I have been lurking around on the wiki and reading love.mouse functions and love.print but none of them helps me understand properly.
I have done this before but for various reasons I haven't touched lua for a while and I need some help to get the wheels rolling.

Thank you for using your time and helping me!
Last edited by nice on Thu Sep 04, 2014 4:54 pm, edited 1 time in total.
:awesome: Have a good day! :ultraglee:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Need help: I want to print x and y position of mouse

Post by Robin »

The relevant functions are [wiki]love.mouse.getPosition[/wiki] and [wiki]love.graphics.print[/wiki]. What do you have so far?
Help us help you: attach a .love.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: Need help: I want to print x and y position of mouse

Post by nice »

I have function love.mouse() set up and I'm looking at the love.mouse.getPosition but even then I don't really understand, I know that you need love.print in here but again I still don't understand where I should where mouse.getPosition should be in there..
:awesome: Have a good day! :ultraglee:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Need help: I want to print x and y position of mouse

Post by Robin »

Please upload a .love, as per the rules, because it's not clear what you have right now.

Also, love.mouse is not a function or a callback. It is a module. If you override it with a function, it's not going to work.
Help us help you: attach a .love.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: Need help: I want to print x and y position of mouse

Post by nice »

Sorry about that, I'm not very used to the forum thing..
And as requested here's my main.lua file
Attachments
main.lua.zip
(377 Bytes) Downloaded 42 times
:awesome: Have a good day! :ultraglee:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Need help: I want to print x and y position of mouse

Post by Robin »

Right. That's not a .love, but close enough.

Add

Code: Select all

local x, y = love.mouse.getPosition()
love.graphics.print("mouse x is: " .. x, 10, 10)
love.graphics.print("mouse y is: " .. y, 10, 40)
to the top of love.draw().

The first line gets the position of the mouse. The second and third line print the position to the screen.

Also, remove this:

Code: Select all

function love.mouse()

end
Once again, love.mouse is a module, not a callback function like love.draw!
Help us help you: attach a .love.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: Need help: I want to print x and y position of mouse

Post by nice »

Thank you so much for your help, I really needed it!
I will remember this till next time.
:awesome: Have a good day! :ultraglee:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 11 guests