How to trigger a Screen Transition from Lua
There are a couple of ways that a screen transition can be called from a Lua script. However I've found the simplest and most effective way is as follows:
The first step is to create a new gde variable at the Application level. You can call this target_screen for example.
Then on the Application level again, you create a new action. This action’s trigger event will be a custom event, called “change_screen” for example.
Since this is a custom event, when you search for change_screen it will not show up since we have not created it yet. Once you are at this position, go ahead and click Add Event.
We will just leave this as is and click Finish.
We want the resulting action to be a Screen Transition. Once you’ve selected Screen Transition as the action, the next dialog will show a text field where you enter the screen name.
Right next to this text field is the green chevron button. If you click this button you can bind a variable to be the value of the text field. So in this case you would set it to the target_screen variable.
Click OK to finish the selection
As you can see the Screen name field now has the context key pointing to the variable we created, in this case “target_screen”.
Now in Lua if you wish to trigger a Screen Transition you would simply set target_screen to the name of the screen you wish to transition to and then send the event “change_screen”.
e.g.
function cb_test_func()
gre.set_value("screen_target", "Screen2")
gre.send_event("change_screen")
end
This allows you to have more dynamic control over how you handle your screen transitions and is a very useful approach to take with any application you create.
Comments
Please sign in to leave a comment.