Well, when you launch the project, manager.open is run once in scene.lua. This is presumably the place that you are having your issues in.
I added the following modifications to check what each value was:
Code: Select all
function manager.open(n)
if not scene[n] then
manager.load(n)
end
list:setBack(scene[n]) -- in setBack() list.back is correct
-- here list.back can be equal to scene.Game
-- and can be equal to scene.Setting
-- simultaneously.
print(list.front, scene.Game, scene.Setting)
if list.front == scene.Game then print("list.front and scene.Game share same value") end
if list.front == scene.Setting then print("list.front and scene.Setting share same value") end
end
Upon launching the project, list.front has a value ("StartPage" scene I presume), while scene.Game and scene.Setting are both nil.
Then, I clicked the "Start" button on the screen, and then "Setting". This made those if-then-prints I added both launch twice, and both times scene.Game and scene.Setting are nil. As such, whatever your code is doing, it's making list.front, scene.Game and scene.Setting all become nil, which does indeed fulfill the conditions for both if-statements that I added to be true. Nil equals nil is true, after all.
I didn't dig too deep into your code to find what the issue might be, but I presume you are deleting scenes somewhere, and you aren't accounting for this. Whether this is a bug or oversight, you might know better. Without digging further, as a solution, you might want to check if the value of scene.Game or scene.Setting is nil, before checking their value against list.front. For example:
Code: Select all
if scene.Game ~= nil and scene.Game == list.front then
-- do things
end
-- alternatively, if you can be sure that scene.Game can never be false (boolean):
if scene.Game and scene.Game == list.front then
-- do things
end
Unrelatedly to the issue you are having, I think your List:erase (in list.lua) has a bug in it:
Code: Select all
function List:erase(e)
if self[1][e] then
self[2][self[1][e]] = self[2][e]
elseif e == self.front then
self.front = self[2][e]
end
if self[2][e] then
self[1][self[2][e]] = self[1][e]
elseif e == self.back then
self.back = self[1][e]
end
self[1][e] = nil -- error: table index is nil
self[2][e] = nil
end
I believe your code is not accounting for the possibility that e may be nil. This makes your project crash if I click on some of the menu items displayed. As such, you might want to add some if-guard that makes the code return early.