Page 1 of 1

Menu buttons won't work ?

Posted: Mon Jul 29, 2013 9:59 pm
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.

Re: Menu buttons won't work ?

Posted: Mon Jul 29, 2013 10:37 pm
by DaedalusYoung
What error do you get? Could you upload a .love file?

Re: Menu buttons won't work ?

Posted: Tue Jul 30, 2013 12:07 am
by Aamer13
When I press begin :
menu.lua:23: attempt to index field 'medium' ( a nil value)

Re: Menu buttons won't work ?

Posted: Tue Jul 30, 2013 1:35 am
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).

Re: Menu buttons won't work ?

Posted: Tue Jul 30, 2013 1:44 am
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'

Re: Menu buttons won't work ?

Posted: Tue Jul 30, 2013 2:31 am
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.

Re: Menu buttons won't work ?

Posted: Tue Jul 30, 2013 2:38 am
by Aamer13
Works perfectly now , Thanks a bunch :D