Page 1 of 1

Delete Spawned Object

PostPosted: Sat Sep 12, 2009 2:46 am
by Torn
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:

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

Re: Delete Spawned Object

PostPosted: Sat Sep 12, 2009 4:08 am
by niffirg1
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.

Re: Delete Spawned Object

PostPosted: Sat Sep 12, 2009 5:32 am
by Torn
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.

Re: Delete Spawned Object

PostPosted: Sat Sep 12, 2009 8:28 am
by standardtoaster
If everything goes according to schedule, I can probably get this done for you.

Re: Delete Spawned Object

PostPosted: Sat Sep 12, 2009 11:03 am
by Torn
Thanks. I originally thought that someone could just tell me, not that people would actually have to go and work on it! :P Thank you to both of you.

Re: Delete Spawned Object

PostPosted: Sun Sep 13, 2009 2:57 am
by standardtoaster
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.

Re: Delete Spawned Object

PostPosted: Fri Sep 18, 2009 3:41 am
by Torn
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. :P

Re: Delete Spawned Object

PostPosted: Fri Sep 18, 2009 3:58 am
by standardtoaster
You're welcome for the script. If there is any way that I can make it easier for you to use please tell me.

Re: Delete Spawned Object

PostPosted: Sun Sep 20, 2009 8:12 pm
by algadoodle123
is this algodoo only...

i tried it on phun, but after the two seconds, it crashed the program

Re: Delete Spawned Object

PostPosted: Sun Sep 20, 2009 8:29 pm
by tatt61880
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. :D

Re: Delete Spawned Object

PostPosted: Sun Sep 20, 2009 9:04 pm
by cdh473
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 :\)

Re: Delete Spawned Object

PostPosted: Mon Sep 21, 2009 1:09 pm
by Sniperkasa
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..)

Re: Delete Spawned Object

PostPosted: Tue Sep 22, 2009 2:34 am
by algadoodle123
thanks...
i changed the code to make the density 0.00000001 instead

Re: Delete Spawned Object

PostPosted: Tue Sep 22, 2009 2:35 am
by standardtoaster
Changing the density in the script works as well. ;) BTW I'm going to upload this to Algobox and remove the IOJ link.

Re: Delete Spawned Object

PostPosted: Sun Sep 27, 2009 3:32 am
by algadoodle123
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 :(

Re: Delete Spawned Object

PostPosted: Sun Sep 27, 2009 4:22 am
by standardtoaster
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. ;)

Re: Delete Spawned Object

PostPosted: Sun Sep 27, 2009 11:13 pm
by algadoodle123
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

Re: Delete Spawned Object

PostPosted: Sun Sep 27, 2009 11:24 pm
by Ian151
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?