Lua and timer example

Crank Storyboard Designer samples and code snippets.

Moderator: jamiev

Lua and timer example

Postby jason » Fri Feb 05, 2010 9:41 am

You can download a sample of this from this post

http://cranksoftware.com/forums/viewtopic.php?f=4&t=27
User avatar
jason
 
Posts: 132
Joined: Mon Nov 02, 2009 4:53 pm

Re: Lua and timer example

Postby timmac » Tue Apr 10, 2012 12:14 pm

I am having trouble getting a timer to fire using a similar method.

I want to have an application timer that fires every 2 seconds until the application quits.

I add an application action gre.init with an Action Type of Timer and a context of Application:
name="uisTimer", rtime=1000, repeat=2000, count=0

Then I created an action of timer.uisTimer with an Action Type of Lua Script and a context of Application
and point it to my uis_timer Lua Function which is simply defined as:

function uis_timer()
print("uis_timer")
end

I never see the print of uis_timer in the console.

What am I missing?

Note: I do have another gre.init action in the application that points to another Lua function, but
I deleted it and the timer still does not fire.

Thanks,

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

Re: Lua and timer example

Postby jason » Tue Apr 10, 2012 12:48 pm

The count variable needs to be greater than 1 or -1. The count states how many times the timer will fire, and -1 implies forever.

To stop the timer you can do a timer action with the exact same timer name and all the variables set to 0.

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

Re: Lua and timer example

Postby timmac » Tue Apr 10, 2012 1:01 pm

Jason,

I changed the params to:

rtime=100, repeat=1000, and count=-1 and it works, but CrankStoryBoard.pdf for gra.timer states that
for a repeating timer count=0 will work.

Has the api for gra.timer changed?

Thanks,

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

Re: Lua and timer example

Postby jason » Tue Apr 10, 2012 1:38 pm

I think that this was a change made a little while ago that was missed on the docs update.

Sorry about that. I'll put in a bug report to get this corrected.

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


Return to Samples

Who is online

Users browsing this forum: No registered users and 0 guests