Changing screens from LUA

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

Changing screens from LUA

Postby jason » Wed Feb 03, 2010 9:34 am

Here is a simple example of changing screens from within a LUA function depending on which key was pressed.

Just unzip the attached zip somewhere, then go
file-> import->Storyboard Embedded Engine (GAPP)
And just point it at the gapp file in the root directory of the unzipped archive.

In this example I use a variable for the screen_name of the screen fade action. Then I trigger all the screen transitions with a single custom event.

The other way do do this is to make a new unique event name for each screen you want to change to. Then the simply select the newly created event type and tie it directly to the desired action. Then just send the correctly named event depending on where you want to go.


This is what the key press function looks like in example :

function key_press(mapargs)
local ev = mapargs["context_event_data"]
local key_char = string.format("%c", ev["code"])
local data = {}

print("Key press code: " .. ev["code"] .. " char: " .. key_char)

if key_char == 'S' then
data["screen_name"] = "settings_screen"
elseif key_char == 'M' then
data["screen_name"] = "music_screen"
elseif key_char == 'P' then
data["screen_name"] = "photo_screen"
end

gre.set_data(data)
gre.send_event("change_screen")
end
Attachments
Key_Press_Example.zip
Key Press Example GAPP file
(33.96 KiB) Downloaded 845 times
User avatar
jason
 
Posts: 190
Joined: Mon Nov 02, 2009 4:53 pm

Re: Changing screens from LUA

Postby cguthrie » Tue Aug 09, 2011 1:12 pm

Hi All,

I attempted the second solution and received the following error: "Event buffer full, dropping [_gre._io_cb]" and then none of the actions I had created worked. Did I do something wrong? or do I just have too many screens?

also how would you recommend doing a one second wait in lua?

thanks,
cguthrie
cguthrie
 
Posts: 24
Joined: Thu Jun 30, 2011 7:27 pm

Re: Changing screens from LUA

Postby jason » Tue Aug 09, 2011 1:59 pm

The "Event Buffer full" means that the event queue overflowed. In version 1.2 the event queue is a static size a can only be grown with command line option to sbengine -oio_mgr,queue_size=4096 (default is 1024). In 1.3 we made the queue auto grow, unless you specified a queue_size on the command line. So you shouldn't see this error is 1.3.

To wait for 1 second in Lua it's best to create an external timer. If you use the os.sleep() call you will block the main tread of the application making it unresponsive.

If your goal is to have the screen up for one second and then switch to another screen via Lua the best way would to create a timer action on the gre.screenshow.post event (set the scope to Screen) that has count of 1 and 1000ms. Then on the timer event (timer.NAME will appear in the event list after it's created) call your Lua function to advance the screen.

Jason
User avatar
jason
 
Posts: 190
Joined: Mon Nov 02, 2009 4:53 pm

Re: Changing screens from LUA

Postby thomas » Tue Aug 09, 2011 3:45 pm

One thing to note about the event queue diagnostic coming out. In general unless you are pushing through a large number of events (ie many repetitive calls to gre.send_event() in the context of a single Lua Action) when you see this message it is an indication that something is likely not working as you expected. In this particular case, the callback event not being queue'able may be an indication that your timer is configured with such a short time interval (time is in milliseconds, not seconds) that it is more or less firing continuously.

You can increase the verbosity level (number of v's to sbengine, ie sbengine -vvvvvv) to get additional diagnostic information about the flow of events and triggering of actions in the system as a debugging tool.
With the Storyboard 1.3 release we are also providing an enhanced logging plugin that can capture some additional performance detail.

Hope this helps,
Thomas
thomas
 
Posts: 127
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Re: Changing screens from LUA

Postby timmac » Mon Apr 23, 2012 1:06 pm

Occassionally, when I run this example I will get the following warning:

Key press code: 109 char: m
DBG1 (0):IO Trigger event [change_screen]
DBG1 (0):IO Trigger event [change_screen]
DBG1 (0):IO Deliver event [change_screen]
DIAG (0):IO Callback 0x0040ac60(change_screen, 0003c4f48)
DIAG (0):ACTION: Action [gra.screen.fade]
WARN (0):ACTION: Missing action handler [gra.screen.fade] ... missing a plugin?
DBG1 (0):IO Trigger event [transition]
DBG1 (0):IO Deliver event [transition]
DIAG (0):IO Callback 0x0040ac60(transition, 0003c4f48)
DIAG (0):IO Callback 0x0040358f(transition, 0003c51e8)
INFO (0):Transition: frames=30 duration=1013 fps=29.62
DBG1 (0):IO Trigger event [gre.screenshow.post]
DBG1 (0):DBG1 (0):IO Trigger event [gre.screenhide.post]IO Trigger event [gre.screenshow.post]

What would cause this? The screen fade plugin is in the project and it works 99% of the time.

Thanks,

Tim
timmac
 
Posts: 42
Joined: Wed Mar 14, 2012 1:21 pm

Re: Changing screens from LUA

Postby thomas » Mon Apr 23, 2012 2:16 pm

In general this error means that the Storyboard Engine can't locate an action provider that exposes the specified action.
Generally this occurs because the plugin that provides the action isn't included in the GRE_PLUGINS list/directory.

There was a bug that was addressed in an earlier Storyboard Engine release that had a glitch in the plugin processing,
but that was several releases ago (~1.2 timeframe).

Are you seeing this error launching from Designer or running on the target hardware? If the target hardware system,
what is it configured as (ie Linux, ARM, fbdev)

Thanks,
Thomas
thomas
 
Posts: 127
Joined: Mon Nov 02, 2009 4:32 pm
Location: Ottawa

Re: Changing screens from LUA

Postby timmac » Tue Apr 24, 2012 10:03 am

Thomas,

I see this intermittently running from Designer under Windows XP.

Thanks,

Tim
timmac
 
Posts: 42
Joined: Wed Mar 14, 2012 1:21 pm

Re: Changing screens from LUA

Postby Ray » Wed Jan 25, 2017 10:07 am

Hi,

I went to the Lua example posted by Jason at 2010, in which screen change is done by sending custom event.
Now in 4.2.1(or the coming 5.0), can we trigger screen change directly from Lua API?

Thank you
Ray
 
Posts: 41
Joined: Wed Apr 06, 2016 3:32 pm

Re: Changing screens from LUA

Postby MikeMarchand » Wed Jan 25, 2017 10:15 am

Hi Ray,

Screen changes are still done using Storyboard events in 5.0.

Cheers,
Mike
MikeMarchand
 
Posts: 17
Joined: Wed Jan 21, 2015 3:33 pm

Re: Changing screens from LUA

Postby stubbornthings » Thu Oct 26, 2017 3:46 pm

I'm trying to open a new screen using LUA but I can't get it to work. I've tried using the gre.send_event("change_screen") example above but it doesn't work. I'm using 5.0.

Is this the only way to change the screen using LUA or am I missing something?

Thanks.
stubbornthings
 
Posts: 12
Joined: Tue Aug 02, 2016 3:25 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron