Events: Timers, Alarms, Cycles

About advanced scenes, and the Thyme scripting language used in Algodoo.

Events: Timers, Alarms, Cycles

Postby Kilinich » Wed Oct 20, 2010 7:15 pm

I've release 2-nd version of my events lib.
It's faster, have more functions.

http://www.algodoo.com/algobox/details.php?id=47506
http://www.algodoo.com/algobox/details.php?id=47509

Just load it as phunlet in your scene and type in console desired command:

List of scene.my. objects

Sim-time functions:
All events automatically removing from queue after occurring (if no repeat)

newAlarm := (start_time:float, {{action}}) - schedule an action in particular sim.time
example: scene.my.newAlarm (2, {{scene.addBox({pos := [0,0]})}}) will spawn box at 2-nd sec of simulation

newTimer := (timer:float, {{action}}, repeat:bool) - schedule an action after some time on optionally repeat it forever
example: scene.my.newTimer(1,{{app.background.skyColor = app.background.skyColor * [0.99,0.99,0.99,1]}}, true) will make background darker every second from the moment it created.

newQueue := (start:float, cicle:float, count:int, {{action}}) - schedule some counted actions
example: scene.my.newQueue (10, 1, 5, {{scene.my -> {a = a + b}}}) - will wait 10 second from this moment and then five times increase a by b with 1 sec delay

newWhile := (cicle:float, {{while_cond:bool}}, {{action}}) - classic while..do cycle
example: scene.my.newWhile (0.5, {{app.mousepos(1) > 0}}, {{scene.addCircle({pos := app.mousePos}) }}) - summon circles every 1/2 sec until mouse is in upper than "horizont"

All "new..." functions returns event ID so you can manipulate with it.
Also, I recommend always use geval() then creating new events.

evDelete := (ID:int) - remove event by ID

Real-time functions (same meaning, but sim-independent):
All events are persistent and stay forever until you delete it with scene.my.rtDelete(ID) command

newRtAlarm := (start_time:float, {{action}})
newRtTimer := (timer:float, {{action}}, repeat:bool)
newRtQueue := (start:float, cicle:float, count:int, {{action}})
newRtWhile := (cicle:float, {{while_cond:bool}}, {{action}})


Sim control variables

halt :bool
scene.my.halt = true will stop sim and forbid to start it (set false to disable this mode)

nonStop :bool
scene.my.nonStop = true will run sim and block it from stopping by space/play button (set false to disable this mode)

Design-time functions
evClear, rtClear - just clear all events completely
evDisable - remove hook so events engine just dies
evEnable - set hook back to app.background.cloudOpacity
rtInit - re-initialize realtime events so schedule will be activated on next scene load.
Last edited by Kilinich on Thu Oct 21, 2010 6:22 am, edited 2 times in total.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Events: Timers, Alarms, Cycles

Postby Kilinich » Wed Oct 20, 2010 8:02 pm

Small demo showing possibilities of events:
Rating: rated 6.1
Filesize: 7.69 kB
Comments: 1
Ratings: 3
download


Plus, my latest BBrobot and Chapaev scenes use it for AI.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Events: Timers, Alarms, Cycles

Postby kilebantick » Thu Oct 21, 2010 3:18 am

Very nice! Will definately use this, even if i have to think of new ideas to use it with! :thumbup:
Image
User avatar
kilebantick
 
Posts: 1267
Joined: Tue Sep 01, 2009 9:50 am

Re: Events: Timers, Alarms, Cycles

Postby Nait » Thu Oct 21, 2010 4:59 am

OMF, I tried to understand something in it and failed...
But, however, that doesn't prevent me from using it! :D
I don't know where I can use those function, but some ideas are coming to my head... :)

PS I think, I can better my smoke simulator with it :) I'm going and trying it :)
User avatar
Nait
 
Posts: 224
Joined: Fri Oct 30, 2009 1:56 am
Location: Eastern Russia, Vladivostok


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests