time of event help?
11 posts • Page 1 of 1
time of event help?
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
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: time of event help?
Make sure that the object has its controllerAcc set to zero.
Or you can use a laser.
- 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} : {}}
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: time of event help?
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)
-
Fujitsu - Posts: 328
- Joined: Tue Sep 01, 2009 12:28 am
- Location: Canada
Re: time of event help?
Yeah. Sorry about that.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: time of event help?
What are you having trouble with?
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: time of event help?
I put the script and squeze my own script but it doesn't spawn anything then
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: time of event help?
Could you please post your current script?
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: time of event help?
You're welcome. I just edited the script to make it slightly easier to use.
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.
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. I'm somewhat proud of what I came up with in five minutes.
- 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. I'm somewhat proud of what I came up with in five minutes.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: time of event help?
Thank you! That was a GREAT explanation Thanks it's working like a beauty now
make sure to check out my work.
-
Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
11 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 22 guests