Menu buttons won't work ?

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
Aamer13
Prole
Posts: 10
Joined: Mon Jul 29, 2013 9:52 pm

Menu buttons won't work ?

Post by Aamer13 »

I recently started using love2d and came up with a slight problem.
My game starts with a menu that both have buttons (Begin & Quit).
You can press the button but it leads to an error page?
Please help , this is my first project using love2d :)

I have uploaded my menu and main code and if needed i can upload a player code as well.
Attachments
Main.lua
This is my main code
(548 Bytes) Downloaded 146 times
menu.lua
This is the page with the buttons that are not working.
(575 Bytes) Downloaded 143 times
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Menu buttons won't work ?

Post by DaedalusYoung »

What error do you get? Could you upload a .love file?
Aamer13
Prole
Posts: 10
Joined: Mon Jul 29, 2013 9:52 pm

Re: Menu buttons won't work ?

Post by Aamer13 »

When I press begin :
menu.lua:23: attempt to index field 'medium' ( a nil value)
Attachments
Game.love
(1.45 KiB) Downloaded 131 times
Shanulu
Prole
Posts: 21
Joined: Mon Jun 24, 2013 11:34 pm

Re: Menu buttons won't work ?

Post by Shanulu »

Something I can help with, yay! You error is on line 23 where you call v.medium. You dont have a medium. I think what you want to call is v.text (the text of your button).
Aamer13
Prole
Posts: 10
Joined: Mon Jul 29, 2013 9:52 pm

Re: Menu buttons won't work ?

Post by Aamer13 »

So this is what i changed it into and now it shows : menu.lua:23: attempt to call method 'getwidth' ( a nil value)
VVVVVVV
function button.click(x,y)
for i,v in ipairs (button) do
if x > v.x and
x < v.x + v.text:getWidth(v.text) and
y > v.y and
y< v.y + v.text:getHeight() then
if v.id =='Quit' then
love.event.push ('quit')
end
if v.id =='Begin' then
gamestate = 'playing'
Shanulu
Prole
Posts: 21
Joined: Mon Jun 24, 2013 11:34 pm

Re: Menu buttons won't work ?

Post by Shanulu »

My bad: I did it backwards, what you want is

Code: Select all

 x < v.x + medium:getWidth(v.text) and
 y > v.y and
 y< v.y + medium:getHeight(v.text) then.
Aamer13
Prole
Posts: 10
Joined: Mon Jul 29, 2013 9:52 pm

Re: Menu buttons won't work ?

Post by Aamer13 »

Works perfectly now , Thanks a bunch :D
Post Reply

Who is online

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