Error
main.lua:492: attempt to index local 'button' (a number value)
Traceback
main.lua:492: in function <main.lua:486>
[C]: in function 'xpcall'
After launching I can click anywhere on the screen and I get the error. It refers to:
for i,v in ipairs(button.activeId) do
The strange part is, that I use the exact same loop some lines above to draw the buttons on the title screen and it works.
I hope somebody can help me. Thanks!
Here is my .love:
attempt to index local 'button' (a number value)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
attempt to index local 'button' (a number value)
- Attachments
-
- 004.love
- (88.92 KiB) Downloaded 99 times
Re: attempt to index local 'button' (a number value)
It is because the button (as argument from function love.mousereleased) replaces your table called button (one variable cannot refer to two values). Try to rename one of that. There is an example to fix it:
(in the example above I renamed argument button and all its usecases of function love.mousereleased to pressedButton)
Code: Select all
function love.mousereleased(x, y, pressedButton)
if button == 4 then
if gm.screen.i == 2 then
handlerScreenTitle()
end
end
for i,v in ipairs(button.activeId) do
if button[v].isHighlight == true then
if pressedButton == 1 then
button[v].handler()
end
end
end
for i,v in ipairs(object.drawnObjectIds) do
if object[v].isHighlight == true then
if pressedButton == 1 and object[v].handlerL then
object[v].handlerL()
elseif pressedButton == 2 and object[v].handlerR then
object[v].handlerR()
end
end
end
end
Re: attempt to index local 'button' (a number value)
I was going crazy and only because I wasn't taking into account that it was in a function with an argument that had the same name. I feel stupid, but I also learned something. Thank you so much!
Now it works.
Now it works.
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests