Hi guys, I’m new regarding Lua language but this error seems very odd to me. How could this happen?
[lua]
if board[boardRow][boardColumn].arrow then --Line 632
board[boardRow][boardColumn].arrow:removeSelf() --Line 633
[/lua]
main.lua:633: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
…s/main.lua:633: in function <…s/main.lua:604>
?: in function <?:229>
Program stopped (pid: 550).
The if is checking for different than null value and then why it is a null value? What happens?
The point is: If I click once in this tile, it works. The second time it throws the error. So I guess in the first time it removes the object, so why there is still there an .arrow ?
Are you nilling the object after removing it? It probably isn’t nil after you remove it the first time and therefore it still thinks theres something to remove.
the thing with Corona display objects, like image, is they are a hybrid object given aspects from Lua and the underlying C++. the outer “wrapper” of these objects is indeed a plan Lua table, but it also contains properties and methods which are created/used by the C++ side.
when calling removeSelf() on an object, Corona will “clean up” the parts of the Lua table from the C++ side, essentially leaving it like an empty shell. you just need to remember not to use the object again, so setting your reference to ‘nil’ is exactly what is needed.
The point is: If I click once in this tile, it works. The second time it throws the error. So I guess in the first time it removes the object, so why there is still there an .arrow ?
Are you nilling the object after removing it? It probably isn’t nil after you remove it the first time and therefore it still thinks theres something to remove.
the thing with Corona display objects, like image, is they are a hybrid object given aspects from Lua and the underlying C++. the outer “wrapper” of these objects is indeed a plan Lua table, but it also contains properties and methods which are created/used by the C++ side.
when calling removeSelf() on an object, Corona will “clean up” the parts of the Lua table from the C++ side, essentially leaving it like an empty shell. you just need to remember not to use the object again, so setting your reference to ‘nil’ is exactly what is needed.