Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075932 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:13:51 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Destroy instance of object using an id
Pages: [1]
Print
Author Topic: Destroy instance of object using an id  (Read 397 times)
Damian
Level 3
***



View Profile Email
« on: July 15, 2011, 05:29:45 AM »

Hi, I'm venturing into new grounds by posting in this part of the forum.

Here's what I'm trying to do. I create multiple instances of an object and then by selection I'd like to destroy only one of those instances. Now I've read about and have heard that each instance has it's own id. So naturally I think I can use that id to destroy that instance. I could be wrong though.

This however is where I'm stuck. I'd like to store that ID into an array and use a pointer to point to the instance ID that I want to destroy. Pointing to the array is fine, but how do I store an ID in an array? heck, how do I get the ID?

Is there another way of doing this that is perhaps better?

Thanks for your time.
Damian


Logged
ஒழுக்கின்மை
Level 10
*****


Also known as रिंकू.

RinkuHero
View Profile WWW Email
« Reply #1 on: July 15, 2011, 05:32:47 AM »

you get the id with the variable conveniently called "id", or when the object is created

you can destroy an object using its id using "with"

with (object_id) instance_destroy();

you can store an id in an array just like you store anything else in an array

for instance:

bullet_id = instance_create(75, 35, obj_bullet);
arrayname[424] = bullet_id;

if you wanted to put all the bullet id's into a bullet array you could also do

global.i = 0;
with (obj_bullet) {
 bullet_array[global.i] = id;
 global.i += 1;
}

you'd then have an array called bullet_array with all the id's of all the bullets in it

if for some reason you wanted an array with the id's of every object in the game rather than just the bullets, you'd just replace obj_bullet with "all" above
Logged

Damian
Level 3
***



View Profile Email
« Reply #2 on: July 15, 2011, 06:16:48 AM »

Thank you.
I feel pretty stupid. Looking at your code I was quite close, but it works like a charm now.
 Hand Thumbs Up Left
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic