How to show and hide screens from Lua
User Question :
There has GOT to be a way to switch between screens from Lua, but I can't figure it out.
I know how to do it from an action due to an action.
Can someone tell me how to do it, please?
Thanks
Answer :
There isn't a way to call a screen transition directly from Lua.
You can create a custom event such as "HOME_SCREEN" and then have it trigger a transition to the home screen when you call gre.send_event("HOME_SCREEN")
If there are too many screens and you don't want to set up an event for each screen you can create a generic "change_screen" event and have it trigger a transition at the application context and make the screen name a variable. Then simply set the variable with the new screen name and trigger the event.
Comments
Just to add to Jason's post the custom event in this case could also be created as type 'Self' so that it is more obvious that this is self-triggering event (the arrow on the event icon is pointing down). Sending an event like this conditionally from a Lua function is a great way to create a dynamic navigation flow for example based on application state.
Using this technique you can then add multiple actions etc on the back of this trigger event arriving.
Take a look at the 'Buttons and Sliders' sample that we bundle with the Storyboard install for how POWER_ON and POWER_OFF events are used to (self) trigger multiple actions.
Garry
Please sign in to leave a comment.