Delete Spawned Object
18 posts • Page 1 of 1
Delete Spawned Object
Hi,
Can someone please tell me how you write a script that will delete a spawned object after a set period of time? This is my existing script:
I want to add something to this that will delete the spawned circle after whatever time value I put in. Can someone please help?
Thanks,
Torn
Can someone please tell me how you write a script that will delete a spawned object after a set period of time? This is my existing script:
- Code: Select all
(e)=>{
scene.addCircle({ radius := 5; density := 2.0; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [x = 0, y = 100]; pos := e.pos }) }
I want to add something to this that will delete the spawned circle after whatever time value I put in. Can someone please help?
Thanks,
Torn
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: Delete Spawned Object
Um i dont think i can delete it unless the density = 0 thing doesnt crash your computer otherwise you could JUst make the opacity and collideset nothing. You would have to do a if statement concering sim.time and the spawned objects color. I will work on it.
-
niffirg1 - Posts: 376
- Joined: Mon Aug 31, 2009 10:31 pm
- Location: The Great American South!
Re: Delete Spawned Object
Great, thank you! You can use AirFrictionMult = NaN to delete the object, I just need to know how to structure the thyme code to do it.
Last edited by Torn on Sat Sep 12, 2009 11:02 am, edited 1 time in total.
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: Delete Spawned Object
If everything goes according to schedule, I can probably get this done for you.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Delete Spawned Object
Thanks. I originally thought that someone could just tell me, not that people would actually have to go and work on it! Thank you to both of you.
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: Delete Spawned Object
Timer script:
Spawn script:
File since Algobox is down. http://ioj.com/v/95vs3 In the timer script you can change the "2" after the >= sign to however long you want it to wait.
- Code: Select all
(e)=>{
sim.time - e.this.controllerAcc >= 2 ? { Scene.my.deleteDensity = 0; e.this.controllerAcc = sim.time } : {Scene.my.deleteDensity = 2} }
Spawn script:
- Code: Select all
(e)=>{
scene.addCircle({ radius := 1; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos }) }
File since Algobox is down. http://ioj.com/v/95vs3 In the timer script you can change the "2" after the >= sign to however long you want it to wait.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Delete Spawned Object
standardtoaster wrote:Timer script:
- Code: Select all
(e)=>{
sim.time - e.this.controllerAcc >= 2 ? { Scene.my.deleteDensity = 0; e.this.controllerAcc = sim.time } : {Scene.my.deleteDensity = 2} }
Spawn script:
- Code: Select all
(e)=>{
scene.addCircle({ radius := 1; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos }) }
File since Algobox is down. http://ioj.com/v/95vs3 In the timer script you can change the "2" after the >= sign to however long you want it to wait.
Wow, thank you! It is a bit confusing, so I'll have to work out how to implement it.
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: Delete Spawned Object
You're welcome for the script. If there is any way that I can make it easier for you to use please tell me.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Delete Spawned Object
is this algodoo only...
i tried it on phun, but after the two seconds, it crashed the program
i tried it on phun, but after the two seconds, it crashed the program
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
-
algadoodle123 - Posts: 66
- Joined: Tue Sep 08, 2009 6:04 pm
Re: Delete Spawned Object
algadoodle123 wrote:is this algodoo only...
i tried it on phun, but after the two seconds, it crashed the program
Yes, it is.
density = 0 causes the crash of the program with Phun Edition beta 5.28.
However this code works well with Algodoo 1.6.0. i.e. This glitch (about density = 0) has been fixed at Algodoo 1.6.0.
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Delete Spawned Object
Yeah, and density=NaN deletes that object and every other one bonded to it, which is good for destroying larger mechanisms.
(that's in my experience, may just be a bug :\)
(that's in my experience, may just be a bug :\)
Please excuse my posts. I am extremely stupid.
-
cdh473 - Posts: 816
- Joined: Tue Sep 01, 2009 12:37 am
- Location: Yes
Re: Delete Spawned Object
I believe what happens on density = NaN is that because the object has no density, it will neither exist, and it will be.. a lot lighter then air, meaning it will try to come ontop of eternity. (I suppose..)
If you have a question, have a dollar and call somebody that cares.
No really just PM me if you have a problem
No really just PM me if you have a problem
-
Sniperkasa - Posts: 493
- Joined: Tue Sep 01, 2009 5:34 pm
- Location: The bottom of a lake.
Re: Delete Spawned Object
thanks...
i changed the code to make the density 0.00000001 instead
i changed the code to make the density 0.00000001 instead
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
-
algadoodle123 - Posts: 66
- Joined: Tue Sep 08, 2009 6:04 pm
Re: Delete Spawned Object
Changing the density in the script works as well. BTW I'm going to upload this to Algobox and remove the IOJ link.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Delete Spawned Object
I can only have on "deleting" circle on the simulation at a time for them to delete...
I can't make a rocket with deleting fuel if there is only one "fuel" circle
I can't make a rocket with deleting fuel if there is only one "fuel" circle
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
-
algadoodle123 - Posts: 66
- Joined: Tue Sep 08, 2009 6:04 pm
Re: Delete Spawned Object
algadoodle123 wrote:I can only have on "deleting" circle on the simulation at a time for them to delete...
I can't make a rocket with deleting fuel if there is only one "fuel" circle
Of course you can.
- Code: Select all
scene.addCircle({ radius := 1; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos })
As you can see, that is the current script. Let's say that you want to spawn 2 circles. You would select your current script, copy and paste it. Don't forget to separate the scripts with a semicolon.
- Code: Select all
scene.addCircle({ radius := 1; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos }); scene.addCircle({ radius := 1; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos })
This will spawn two circles instead of one. Now let's say that the radius that they are spawning with is to large. You can change the after the radius to your own number.
- Code: Select all
scene.addCircle({ radius := 0.5; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos }); scene.addCircle({ radius := 0.5; density := {Scene.my.deleteDensity}; restitution := 0.5; friction := 0.5; color := [0, 0, 0, 0.5]; vel := [0, 0]; pos := App.mousePos })
This will spawn two circles with a radius of 0.5. I hope that you get it from here.
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: Delete Spawned Object
I can't power a rocket with only one batch of fuel...
can I?
edit: never mind... the circles all push against each other continually to make thrust... ill just put the delete code in the spawned circles rather than the probe
can I?
edit: never mind... the circles all push against each other continually to make thrust... ill just put the delete code in the spawned circles rather than the probe
Last edited by algadoodle123 on Mon Sep 28, 2009 2:10 pm, edited 1 time in total.
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
-
algadoodle123 - Posts: 66
- Joined: Tue Sep 08, 2009 6:04 pm
Re: Delete Spawned Object
why not spawn again and again? the fuel will delete after each cycle of the timer. If you keep spawning fuel, it will do its thing and then it will delete itself after a while. That should work, right?
-
Ian151 - Posts: 47
- Joined: Tue Sep 01, 2009 12:02 am
18 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests