Page 1 of 1

Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 5:02 pm
by Dadasas
I want to make something spawn a circle and then the circle is erased in a second without the circle hitting anything, Is it possible?

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 5:11 pm
by KarateBrot
Code: Select all
(e) => { scene.addcircle({collideset := 0; airfrictionmult := NaN}) }

But you need air friction for it to work

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 6:01 pm
by Dadasas
I want the circle to stay there for a second or more like 10 seconds, I don't want scene.my thing, I also want it possible to make more than one at the same time.

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 6:32 pm
by RA2lover
you can use the for(number of times you want to, (variable if you want to change something according to spawns)=>{script to be executed}) function(a looping structure) to avoid having to type everything tons of times.

for the time-limit, you might want to use a built-in variable, stored in the circle itself, and put on the density value something like that
{timetodeleteobject <= sim.time ? 0 : density of normal object}

also, i'm assuming you're using algodoo, as using density = 0 in A:PE can cause crashes.

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 7:18 pm
by Dadasas
Hmm, So if I wanted to make it be deleted in 5 sim.time units after being spawned , how would I do that?

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 8:27 pm
by KarateBrot
if you want to spawn an object before the last one gets deleted it can be a problem because the script will be deleted from the first object that was spawned.

If you want it to last 5 time units and if only one circle every 5 units is spawned this works:
Code: Select all
(e) => { scene.addcircle({spawntime := sim.time; density := {(sim.time - spawntime) > (5.0 / sim.frequency) ? {0} : {2.0}} }) }


But are you using phun or algodoo? This is important to know.

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 8:35 pm
by Dadasas
Algodoo. Thanks for all your help.

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 8:36 pm
by KarateBrot
Ok it will work then. Otherwise you'd have to use airfrictionmult = NaN instead of density = 0
try it. If it's too fast use a higher number than 5.0

And you really want to delete it after 5 time units and not 5 seconds or something like that?

Re: Spawning a circle then deleting it.

PostPosted: Sat Dec 19, 2009 9:10 pm
by Dadasas
Okay , but why can it only spawn one at a time?

Re: Spawning a circle then deleting it.

PostPosted: Sun Dec 20, 2009 3:40 am
by KarateBrot
You can spawn more at a time but then only the last spawned will be deleted. the others will stay because once a new object is spawned before the last one is deleted the script gets deleted from the old one and only works for the new spawned object. i don't know why this happens. maybe a bug.

Re: Spawning a circle then deleting it.

PostPosted: Sun Dec 20, 2009 6:48 pm
by Dadasas
Hmm, well my problem is solved, Thanks everybody!
EDIT : One quick question, is it possible to make an if statement that ask if the other thing is water?

Re: Spawning a circle then deleting it.

PostPosted: Sun Dec 20, 2009 11:59 pm
by blahblah200
Yes - e.other + "" is how you work out what it is (I am not sure if I have spelt it right) - so this is the code -
Code: Select all
e.other + "" == "water" ? {What happens if it IS water} : {What happens if it ISN'T water}


You can also make it so it can recognise what type of geomitery the other thing is -
if it's a plane - e.other + "" equals "plane"
if it's a box - e.other + "" equals "box"
if it's a polygon - e.other + "" equals "polygon"
and so on - you get the idea

Re: Spawning a circle then deleting it.

PostPosted: Mon Dec 21, 2009 12:09 am
by KarateBrot
No that doesn't work. I already tried it. I only know this kind of code for the normal geometries but not for water. I also tried "splash of water" but that doesn't work, too