How to delete objects using a script

Post your tutorials here.

How to delete objects using a script

Postby sOvr9000 » Tue Apr 21, 2015 1:44 am

At first, I was having trouble with figuring out how to delete objects with a script. After some experimentation, it seems that the perfect way to do it is to set an object's timeToLive property equal to 0.
I crossed this problem when I decided to program a star to absorb the mass of any planetary object that hit it, and the code for the star's onCollide event looks like this:

Code: Select all
(e)=>{
    radius = math.sqrt(radius ^ 2 + (e.other.density / density) * e.other.radius ^ 2);
    e.other.timeToLive = 0
}


As you can see, I'm deleting the other circle's instance by eliminating all the time it has to live.
Anyway, I hope this is useful to anyone who's new to programming with Algodoo! (I'm new myself)
sOvr9000
 
Posts: 1
Joined: Tue Apr 21, 2015 1:07 am

Re: How to delete objects using a script

Postby pnvv » Tue Apr 21, 2015 8:26 pm

Interesting.
Image

(/)(°,,,°)(/)
User avatar
pnvv
 
Posts: 670
Joined: Tue Aug 26, 2014 11:46 pm
Location: Disunited States of America

Re: How to delete objects using a script

Postby Kilinich » Thu Apr 23, 2015 11:48 am

scene.removeEntity()
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: How to delete objects using a script

Postby FRA32 » Sun Aug 09, 2015 2:10 pm

e.other.density = 0 is my typical way
FRA32
 
Posts: 213
Joined: Wed Dec 03, 2014 9:51 pm

Re: How to delete objects using a script

Postby electronicboy » Mon Aug 10, 2015 3:20 am

FRA32 wrote:e.other.density = 0 is my typical way

Don't use that, it causes a memory leak as objects aren't removed from the scene properly, they're just effectlvly set to an invalid state and not cleared from the memory.
We got scene.removeEntity() for a reason
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1693
Joined: Mon Aug 31, 2009 6:18 pm

Re: How to delete objects using a script

Postby pnvv » Mon Aug 10, 2015 3:28 am

Or just use killers. I mean, setting a killer on an object is just the nooby way of typing {scene.removeEntity(e.other)} into onCollide...
Image

(/)(°,,,°)(/)
User avatar
pnvv
 
Posts: 670
Joined: Tue Aug 26, 2014 11:46 pm
Location: Disunited States of America


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest