Unable to use storyboard.gotoScene() in a native.showAlert's onComplete function.

Here is my code:

local tabBarPress(event)  
  
 --handle result of button press in alert view.  
 local function onAlertComplete( event )  
 if "clicked" == event.action then  
 if event.index == 1 then  
 --do nothing, but revert tab bar to the last button that was pressed  
 tabs:pressButton( lastScreenSelected, false )  
  
 elseif event.index == 2 then  
 --go back to login screen  
 storyboard.gotoScene( "screen5" )  
 end  
 end  
 end  
  
 -- Show alert with two buttons  
 local alert = native.showAlert( "Logout", "Are you sure you want to logout?",   
 { "No", "Yes" }, onAlertComplete )  
  
  
 return true  
end  
  

Now if I just put storyboard.gotoScene( “screen5” ) in the tabbar button press that works fine. However if I put it in the onAlertComplete function I get this error:

Runtime error
bad argument #-2 to ‘insert’ (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘insert’
?: in function ‘?’
?: in function ‘gotoScene’
main.lua:1618: in function ‘_listener’
?: in function <?:534>
?: in function <?:229>
Does anyone have any idea what could be happening here?
I need the alert view to make sure the user gets the chance to change their mind if they hit the “logout” tab by mistake.
[import]uid: 84115 topic_id: 33345 reply_id: 333345[/import]

Also the tabBarPress function does also have code to handle various button presses, but the other 4 tab buttons have worked fine for weeks now. Since the logout button works if there is no alert view I don’t think that it would be necessary to show you everything. [import]uid: 84115 topic_id: 33345 reply_id: 132407[/import]

I’ve never seen that before, but you could try to wrap the storyboard.gotoScene() call in a

timer.performWithDelay(5,function() storyboard.gotoScene("screen5") end)  

And see if that works. I don’t know if the native.alert is causing a scope problem or not [import]uid: 199310 topic_id: 33345 reply_id: 132496[/import]

I had actually already tried that, having thought the same thing. No luck.

I’ve made my own popup box in the meantime, but I think this is possibly a bug that could do with fixing. [import]uid: 84115 topic_id: 33345 reply_id: 132503[/import]

If you can reduce the code to a small simple example that demonstrates the problem, and upload the sample project using the “Report a Bug” link above would be quite helpful.

Rob
[import]uid: 199310 topic_id: 33345 reply_id: 132504[/import]

Also the tabBarPress function does also have code to handle various button presses, but the other 4 tab buttons have worked fine for weeks now. Since the logout button works if there is no alert view I don’t think that it would be necessary to show you everything. [import]uid: 84115 topic_id: 33345 reply_id: 132407[/import]

I’ve never seen that before, but you could try to wrap the storyboard.gotoScene() call in a

timer.performWithDelay(5,function() storyboard.gotoScene("screen5") end)  

And see if that works. I don’t know if the native.alert is causing a scope problem or not [import]uid: 199310 topic_id: 33345 reply_id: 132496[/import]

I had actually already tried that, having thought the same thing. No luck.

I’ve made my own popup box in the meantime, but I think this is possibly a bug that could do with fixing. [import]uid: 84115 topic_id: 33345 reply_id: 132503[/import]

If you can reduce the code to a small simple example that demonstrates the problem, and upload the sample project using the “Report a Bug” link above would be quite helpful.

Rob
[import]uid: 199310 topic_id: 33345 reply_id: 132504[/import]

I’ve got just the same problem.
Is anybody who have solved this problme? [import]uid: 104920 topic_id: 33345 reply_id: 145151[/import]

I’ve got just the same problem.
Is anybody who have solved this problme? [import]uid: 104920 topic_id: 33345 reply_id: 145151[/import]

I’ve got just the same problem.
Is anybody who have solved this problme? [import]uid: 104920 topic_id: 33345 reply_id: 145151[/import]

I’ve got just the same problem.
Is anybody who have solved this problme? [import]uid: 104920 topic_id: 33345 reply_id: 145151[/import]

Just encountered this problem. Any fixes or workarounds yet?

It seems if i call a storyboard.purgeScene(…) inside the exitScene function, this error happens. If I remove it, error gone.

The only problem is, I need to purgeScene inside exitScene otherwise, I cannot reloadScene.

Any ideas?

I don’t believe you are supposed to purge a scene from within the scene.  You shouldn’t have to purge a scene to reload it if you have all the right things in the right places. 

Things outside of createScene()/enterScene() only happen once… ever…  unless the scene is removed or un-required.  So putting things at the top like:

    local counter = 0

will only get set once.  When you re-enter that scene, that code will not re-execute.

Code inside of createScene() only executes if the scene is brand new or it’s been purged.   If you are reloading your scene, you probably don’t need to do this every time.  Your scene is already in memory and you’re going to take a small performance hit to get rid of it all and re-create it.    But if objects have  moved and you need to reset them, or values change and they need reset, they won’t be reset when you re-enter because createScene() isn’t executed.

This leaves enterScene() as the magic location where you need to re-set things.  Of course this can cause some visual trauma as things jump around, so we have some other events like willEnterScene() which gives you a chance to move things before the scene is transitioned onto the screen.

Once you get things in the right place you shouldn’t need to purge the scene to reload the scene.

I see. So…

createScene… initialize one-time load assets

willEnterScene… setup before drawing

enterScene… setup after drawing is enabled

Is this logical?

Things worked as expected. One thing I wanted/had to do is clear the scene self.view display group in the exitScene function.

&nbsp;&nbsp;&nbsp; while (self.view.numChildren \> 0) do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.view[1]:removeSelf() &nbsp;&nbsp;&nbsp; end &nbsp;

Just encountered this problem. Any fixes or workarounds yet?

It seems if i call a storyboard.purgeScene(…) inside the exitScene function, this error happens. If I remove it, error gone.

The only problem is, I need to purgeScene inside exitScene otherwise, I cannot reloadScene.

Any ideas?