Variable in overlay scene after adListener is called isn't being updated after user is in Overlay a second time

Greetings,

This is a little long …I’ll try to summarize and simplify as much as possible:

I have scene that calls an overlay.   In that overlay is a menu of sorts, and I have a declaration of variables at top.  yada yada yada…

I’m using a lock system for certain items that you can do a ‘shortcut unlock’ by watching a video (incentivized adverts).  To keep track of which locked items are being hit, I’m using something like this to keep track of them, ‘item[i].id = i’.

One of the declarations at the top I’m using is an unlock number variable, ‘unlockNum=1’ for default value.

When the user touches one of the locks - it finds the ‘.id’ of the item that’s being touched, and then I do ‘unlockNum = id’.  Simple enough.

The advertisement then launches - and in the adListener function , once the user closes the advertisement - I use the unlockNum to figure out which item it just unlocked.

ALL IS FINE if the user is in the overlay for the first time.  I DO NOT DESTROY the overlay, but I Hide it once user is ready to move on.  

Then when the user goes to the overlay (the menu) a second time, third, etc. - and the user tries to click on another lock - The advertisement launches but the ‘unlockNum’ value doesn’t change to the ‘.id’ when I fetch it in the ‘adListener’ function.  If I was in the overlay for first time - then it does change value as expected.

*** I’ve been using ‘print’ statements to help me debug… and it seems that during the second,third,etc. time user goes  to the Overlay - On the touch function (just before the advertisement launches, but still in touch function) - I print( unlockNum ) and the value is reporting correctly (to the item.id).  Then I have a ‘print’ statement in adListener function when it completes, and use print( unlockNum ) and it’s reporting the ‘unlockNum’ value from the first time user is in the overlay (an older value)… HUH???

I’m a bit lost, because the value is correctly updating on the ‘touch event’ but when the advertisement completes, and the adListener gets called, the value is showing the old value from when user was in the Overlay scene for first time…  When the user is in the overlay scene for first time, then everything works as expected… ??? HELP!

If you are not destroying the scene, then scene:create() does not get called and any thing that’s executed in the module’s main chunk will only execute once. On subsequent loads only scene:show() and scene:hide() get called.

I don’t know if that helps, but it feels like this may be the case.

Rob

Right - but the variable is getting updated in the touch function (I use a print statement in touch function of the variable to confirm) which is also in the overlay- even if it’s the second, third, etc. time I visit the overlay.  And I’m updating the value for the variable in the touch function, then the video advertisement gets played.  Then the adListener gets called, and if I print the variable in the adListener function- it’s the older value and won’t update no matter what.

I’ve tried all sorts of things but can’t seem to get this working so for now I’m skipping over it, it makes no sense !

If you are not destroying the scene, then scene:create() does not get called and any thing that’s executed in the module’s main chunk will only execute once. On subsequent loads only scene:show() and scene:hide() get called.

I don’t know if that helps, but it feels like this may be the case.

Rob

Right - but the variable is getting updated in the touch function (I use a print statement in touch function of the variable to confirm) which is also in the overlay- even if it’s the second, third, etc. time I visit the overlay.  And I’m updating the value for the variable in the touch function, then the video advertisement gets played.  Then the adListener gets called, and if I print the variable in the adListener function- it’s the older value and won’t update no matter what.

I’ve tried all sorts of things but can’t seem to get this working so for now I’m skipping over it, it makes no sense !