[RESOLVED] saving and restoring variable value not updating the global after save

Hi,

I have a game which has ads, I have an IAP (working correctly) to remove them. So far so good.

So, I have a variable removeAllAds that will be false until the purchase is complete, the removeAllAds() switches the value to true and stores it.

This works OK

If I manually change the value to true without using the table to save, it works ok.

Issue is it isnt updating the variable value in the global ??? it just returns nil when I print(removeAllAds).

It really is becoming a nightmare for me which is why I am asking for a second pair of eyes.

[lua]

–MAIN.LUA–

_G.storageTable = {}
_G.removeAllAds = storageTable.removeAds

if( io.exists( “saveFile.txt”, system.DocumentsDirectory ) ) then
 
    storageTable = table.load( “saveFile.txt”, system.DocumentsDirectory )
else

   storageTable.removeAds = false
   table.save( storageTable, “saveFile.txt”, system.DocumentsDirectory )

end

function _G.removeTheAds()
    storageTable.removeAds = true
    table.save( storageTable, “saveFile.txt”, system.DocumentsDirectory )

end

 – MAIN LUA AD FUNCTION –

loadAd = function()

– _G.removeAllAds = storageTable.removeAds – ADDED HERE

if removeAllAds == true then
           gameOverScreen()
  else

–load the ad–

end

[/lua]

As always seems I find the solultion before a reply, but as always I like to update the thread incase anybody is interested.

Seems I should be paying more attention to the logic of a situation.

by adding the reference to the table above the conditionals it worked.

[lua]

 _G.removeAllAds = storageTable.removeAds

[/lua]

As always seems I find the solultion before a reply, but as always I like to update the thread incase anybody is interested.

Seems I should be paying more attention to the logic of a situation.

by adding the reference to the table above the conditionals it worked.

[lua]

 _G.removeAllAds = storageTable.removeAds

[/lua]