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.
Menu buttons won't work ?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Menu buttons won't work ?
What error do you get? Could you upload a .love file?
Re: Menu buttons won't work ?
When I press begin :
menu.lua:23: attempt to index field 'medium' ( a nil value)
- Attachments
-
- Game.love
- (1.45 KiB) Downloaded 131 times
Re: Menu buttons won't work ?
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 ?
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'
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 ?
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 ?
Works perfectly now , Thanks a bunch
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests