I have some display images that I need to save after changing scene. So I put them in a table, created a global variable and put the table in there. But they still get cleaned if they are in localGroup, and when I go back to the global variable, the table is there and the keys are still the same, but the values are nil. This crashes my code when I try and reload it. I've also tried creating a newImage everytime the reloadImagesAndSettings function is called, but that screws things up as well.
Is there something I'm missing??
Here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | local function saveImagesAndSettings() print("saveImagesAndSettings() entered") --setting global variable for future use _G["vars"].friendsUnfinished = true local tempTable if _G["vars"].friendsSettings then tempTable = _G["vars"].friendsSettings else tempTable = {} end tempTable[1] = kmf.photoEngaged tempTable[2] = kmf.photoWidth tempTable[3] = kmf.photoHeight tempTable[4] = kmf.maleFemale tempTable[5] = images for k,v in pairs(images) do print("Previous Image being made invisible: ",k,v) images[k].isVisible = false localGroup:remove(images[k]) --this SHOULD prevent deletion upon changeScene --kmf.removeListeners() is unnecessary because that's a normal part of clean-up end print("tempTable",tempTable) --packing away settings into a global variable _G["vars"].friendsSettings = tempTable print("saveImagesAndSettings() exited") end local function reloadImagesAndSettings() print("reloadImagesAndSettings() entered") --unpacking globally saved settings local tempTable = _G["vars"].friendsSettings kmf.photoEngaged = tempTable[1] kmf.photoWidth = tempTable[2] kmf.photoHeight = tempTable[3] kmf.maleFemale = tempTable[4] images = tempTable[5] for k,v in pairs(images) do print("reloading Previous Image: ",k,tostring(v)) images[k].isVisible = true --Simulate transitioning in with localGroup because -- inserting images[k] into localGroup makes them disappear localGroup:insert(images[k]) images[k].x = images[k].x + contentWidth transition.to(images[k], {time = 200, x = (images[k].x - contentWidth) }) kmf.initListeners() kmf.isActive = true end ...unrelated code here end |