Delete an Object by modifying OnCollide

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

Delete an Object by modifying OnCollide

Postby Narya » Mon Jan 04, 2016 6:48 pm

Hi,
Iam a scripting Noobie.
I was looking for a way to destroy/delete an object by using OnCollide.
I did find a way , on the net, and it involves setting density of the object to 0.(e.this.density =1.0) .This approach appears a bit contrived
Is there any other way?
Rgds
Narya
Narya
 
Posts: 2
Joined: Mon Jan 04, 2016 6:37 pm

Re: Delete an Object by modifying OnCollide

Postby T'wind_ » Mon Jan 04, 2016 6:55 pm

the legit way to do it:
Code: Select all
scene.removeEntity(e.other)


Never use density = 0, it causes a memory leak as objects are set to an invalid state and not cleared from the memory.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: Delete an Object by modifying OnCollide

Postby homieeee » Tue Jan 05, 2016 3:31 am

scene.removeEntity(e.other) still causes a memory leak. It's a problem with algodoo, there is no way to delete an object and free memory :? . So setting density to 0 works just as well as any other type of "deleting".
User avatar
homieeee
 
Posts: 14
Joined: Thu Oct 09, 2014 2:13 am

Re: Delete an Object by modifying OnCollide

Postby FRA32 » Wed Jan 06, 2016 6:04 pm

Density and removeEntity delete the objects in a nearly identical way, since algodoo can't clear memory properly, and the objects are in fact removed from the scene when they turn invalid by density or similar(exception is when having negative radius/size :crazy: )
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: Delete an Object by modifying OnCollide

Postby T'wind_ » Wed Jan 06, 2016 9:40 pm

I may be wrong, I got the information from Electronicboy.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: Delete an Object by modifying OnCollide

Postby hiltropper » Tue Jan 12, 2016 6:47 pm

timetolive=0 is also an option, but using density=0 never had any negative effect for me
yup yup
yuuuuuuup
yupyupyupyupyupyupyupyupyyyuuuup
hm... signatures...
hiltropper
 
Posts: 85
Joined: Mon Dec 20, 2010 12:02 pm
Location: Germany

Re: Delete an Object by modifying OnCollide

Postby FRA32 » Tue Jan 12, 2016 8:46 pm

I usually take timetolive=0 nowadays since algodoo uses that itself, so it MUST be kinda legit? Well, usually you don't need to worry, since, if there ARE increased memory leak chances on one of the solutions, then you will still see it only after you deleted over about 1000 objects.
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: Delete an Object by modifying OnCollide

Postby Kilinich » Tue Jan 12, 2016 9:26 pm

From my expirience, onCollide=(e)=>{}; timeToLive=0 is safest way to delete object.
Scene.removeEntity cause postStep event skip :(
Density=0 works well, but there was some negative effects like console warnings...
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Delete an Object by modifying OnCollide

Postby icrls984 » Sat Feb 06, 2016 12:36 am

I believe you can also remove an object by setting it's inertiamultiplier to 0, but I usually use timetolive.
.
User avatar
icrls984
 
Posts: 80
Joined: Thu Jun 13, 2013 6:33 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 9 guests

cron