time of event help?

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

time of event help?

Postby Rideg » Thu Jan 07, 2010 11:50 pm

Hello! i need help with getting like (e)=>{scene.addBox} only happen in a period of time so a box only spawnes every 5 second. I'm dealing with both onCollide and onLaserHit here and help is highly appriciated :)
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: time of event help?

Postby standardtoaster » Fri Jan 08, 2010 1:35 am

Make sure that the object has its controllerAcc set to zero.
Code: Select all
onCollide=(e)=>{(e.this.controllerAcc - sim.time) >= 5 ? {scene.addBox({parameters}); e.this.controllerAcc = sim.time} : {}}

Or you can use a laser.
Code: Select all
onLaserHit=(e)=>{(e.geom.controllerAcc - sim.time) >= 5 ? {scene.addBox({parameters}); e.geom.controllerAcc = sim.time} : {}}
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: time of event help?

Postby Fujitsu » Fri Jan 08, 2010 7:43 am

standardtoaster wrote:
Code: Select all
onCollide=(e)=>{(e.this.controllerAcc - sim.time) >= 5 ? {scene.addBox({parameters}); e.this.controllerAcc = sim.time} : {}}

Code: Select all
onLaserHit=(e)=>{(e.geom.controllerAcc - sim.time) >= 5 ? {scene.addBox({parameters}); e.geom.controllerAcc = sim.time} : {}}


Don't you mean this?:
Code: Select all
(sim.time - e.this.controllerAcc)
Image
Gimmie money.
User avatar
Fujitsu
 
Posts: 328
Joined: Tue Sep 01, 2009 12:28 am
Location: Canada

Re: time of event help?

Postby standardtoaster » Fri Jan 08, 2010 4:35 pm

Yeah. Sorry about that.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: time of event help?

Postby Rideg » Fri Jan 08, 2010 10:40 pm

I can't get it to work :?
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: time of event help?

Postby standardtoaster » Fri Jan 08, 2010 10:41 pm

What are you having trouble with?
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: time of event help?

Postby Rideg » Fri Jan 08, 2010 10:45 pm

I put the script and squeze my own script but it doesn't spawn anything then :(
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: time of event help?

Postby standardtoaster » Fri Jan 08, 2010 10:47 pm

Could you please post your current script?
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: time of event help?

Postby Rideg » Fri Jan 08, 2010 11:09 pm

Never mind just got it;Pthank you;)
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: time of event help?

Postby standardtoaster » Fri Jan 08, 2010 11:18 pm

You're welcome. I just edited the script to make it slightly easier to use.
Code: Select all
Scene.my.TimedEvent=(WT, C, What)=>{(sim.time - c) >= WT ? {what} : {}}

WT stands for wait time; ie. how often do you want the script to happen
C stands for controllerAcc or anything else
What stands for what you want to happen when the result is true.
NOTE: For the "what" you need put curly brackets around it like the example below and you must put e.this/other.whateveryouusedforC = sim.time.

Here's an example.
Code: Select all
Scene.my.TimedEvent(5, e.this.controllerAcc, {         e.this.controllerAcc = sim.time;         Scene.addBox({             pos := App.mousePos;             body := 0;             collideSet := 0         })     })

In the example above, 5 is used for wt, the controllerAcc is used for c, and the box spawning code along with controllerAcc = sim.time for the what. What this code does is subtracts the simulation time from whatever number you were using for c and once it reaches wt, the wait time you specified, it will then use what. :D I'm somewhat proud of what I came up with in five minutes.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: time of event help?

Postby Rideg » Sat Jan 09, 2010 10:50 pm

Thank you! That was a GREAT explanation Thanks it's working like a beauty now :D
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 22 guests

cron