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:
[lua]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[/lua] [import]uid: 10211 topic_id: 8636 reply_id: 308636[/import]