We’ve finished an app that runs as it should in the simulator, and have built it to a device for final testing (we’ve built to both a Nook and a Kindle and had this same issue)
Main.lua is running twice, and so all of our variables are getting created twice, all the event listeners are created twice, and so on… obviously this is not how we want the app to run.
We’ve commented out everything in main.lua except for a print statement and that print statement prints twice as soon as the app loads on device and runs main.lua twice.
We’ve uninstalled Corona and reinstalled, rebooted the computer and the Nook device several times, copied out the text from main.lua and created it in a blank new .lua file, same results - main.lua runs just once in the simulator, but twice through on the device. We’re not using Cider or Glider which I’ve seen in the forums can sometimes cause an issue. We’re using the latest stable build Corona 971.
The real fix would be for main.lua NOT to run twice, but since we’ve tried everything to no avail we decided on a workaround:
if (settings.alreadyRan) then
print(“NOT RUNNING MAIN AGAIN”)
else
– all of our relevant main.lua code here
settings.runOnce()
end
IN SETTINGS.LUA:
function runOnce (event)
if (alreadyRan) then
print “ALREADY RAN”
else
print “FIRST TIME RUNNING”
alreadyRan = true
end
end
The idea was that the second time main.lua ran through, settings.alreadyRan would be true and therefore nothing would run again. We basically put all of our code in the ‘else’ so that it runs the first time but won’t be run a second time. Thought this would work to prevent main.lua from reloading all our assets when it runs the second time through, but all of a sudden we can’t access our functions in Settings (which we have been accessing all along throughout this app and all our other apps and worked just fine until we tried it here).
In the simulator settings.runOnce() works as expected and prints “FIRST TIME RUNNING”
On the device we get this error:
Lua Runtime Error: lua_pcall failed with status: 2, error message is: ?:0: attempt to call field ‘runOnce’ (a nil value)
Any ideas why main.lua is running twice or why we’re getting this runtime error when trying to call our workaround function in settings would be greatly appreciated…