Delete Spawned Object

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

Delete Spawned Object

Postby Torn » Sat Sep 12, 2009 2:46 am

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
Torn
 
Posts: 32
Joined: Tue Sep 01, 2009 8:06 am

Re: Delete Spawned Object

Postby niffirg1 » Sat Sep 12, 2009 4:08 am

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.
User avatar
niffirg1
 
Posts: 376
Joined: Mon Aug 31, 2009 10:31 pm
Location: The Great American South!

Re: Delete Spawned Object

Postby Torn » Sat Sep 12, 2009 5:32 am

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

Postby standardtoaster » Sat Sep 12, 2009 8:28 am

If everything goes according to schedule, I can probably get this done for you.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Delete Spawned Object

Postby Torn » Sat Sep 12, 2009 11:03 am

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.
Torn
 
Posts: 32
Joined: Tue Sep 01, 2009 8:06 am

Re: Delete Spawned Object

Postby standardtoaster » Sun Sep 13, 2009 2:57 am

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.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Delete Spawned Object

Postby Torn » Fri Sep 18, 2009 3:41 am

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
Torn
 
Posts: 32
Joined: Tue Sep 01, 2009 8:06 am

Re: Delete Spawned Object

Postby standardtoaster » Fri Sep 18, 2009 3:58 am

You're welcome for the script. If there is any way that I can make it easier for you to use please tell me.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Delete Spawned Object

Postby algadoodle123 » Sun Sep 20, 2009 8:12 pm

is this algodoo only...

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
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Delete Spawned Object

Postby tatt61880 » Sun Sep 20, 2009 8:29 pm

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
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).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: Delete Spawned Object

Postby cdh473 » Sun Sep 20, 2009 9:04 pm

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 :\)
Please excuse my posts. I am extremely stupid.
User avatar
cdh473
 
Posts: 816
Joined: Tue Sep 01, 2009 12:37 am
Location: Yes

Re: Delete Spawned Object

Postby Sniperkasa » Mon Sep 21, 2009 1:09 pm

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 :)
User avatar
Sniperkasa
 
Posts: 493
Joined: Tue Sep 01, 2009 5:34 pm
Location: The bottom of a lake.

Re: Delete Spawned Object

Postby algadoodle123 » Tue Sep 22, 2009 2:34 am

thanks...
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
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Delete Spawned Object

Postby standardtoaster » Tue Sep 22, 2009 2:35 am

Changing the density in the script works as well. ;) BTW I'm going to upload this to Algobox and remove the IOJ link.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Delete Spawned Object

Postby algadoodle123 » Sun Sep 27, 2009 3:32 am

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 :(
**/\ /\
>( ' ; ' )<***<---------- cat
*((")("))
i'm right-side-up
uʍop-ǝpısdn ɯ,ı
http://www.sherv.net/flip.html
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Delete Spawned Object

Postby standardtoaster » Sun Sep 27, 2009 4:22 am

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. ;)
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: Delete Spawned Object

Postby algadoodle123 » Sun Sep 27, 2009 11:13 pm

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
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
User avatar
algadoodle123
 
Posts: 66
Joined: Tue Sep 08, 2009 6:04 pm

Re: Delete Spawned Object

Postby Ian151 » Sun Sep 27, 2009 11:24 pm

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?
"THE BEST 2 PLAYER SCENE EVER MADE!!!" - ianno
http://www.algodoo.com/algobox/details.php?id=24204
Image
User avatar
Ian151
 
Posts: 47
Joined: Tue Sep 01, 2009 12:02 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 0 guests