• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Adding all objects (not instances) to a ds_list on room start

L

lumini

Guest
Hi there!

I was wondering if it is possible to make a ds_list and populate it on room start with indexes of different objects (from that room).
For instance, in a room are multiple instances of three objects (obj_one, obj_two, obj_three). What I am asking : is there a way just to add those three objects instead of populating a list with indexes of multiple instances ?

Thanks in advance ! :)
 
A

Aura

Guest
<old post removed>

Edit: Just realised what you were asking for.

Code:
if (instance_exists(obj_one)) {
   ds_list_add(data, obj_one);
}
...would do that.

If you want to add the object indexes of all instances present in the room:

Code:
with (all) {
   ds_list_add(data, object_index);
}
If you want to add an object index only once:

Code:
with (all) {
   if (ds_list_find_index(data,object_index) == -1) {
      ds_list_add(data, object_index);
   }
}
 
Last edited by a moderator:
L

leonfook29

Guest
I'm not sure i understand this well. You want to add the object index of the instance instead of the id? It could be done by retrieving the object_index of the instance, and then store it to the list. You could use ds_list_find_index(id, val) to check whether the object_index is stored.

But if you want to store the id, see above.
 
L

lumini

Guest
Something like this, maybe?
Code:
with(all){
  if(ds_list_find_index(global.list,object_index) < 0){
    ds_list_add(global.list,object_index)
  }
}
Exactly what I needed. :) I almost forgot that there is a with() statement... -_-
And thanks everyone on the replies! :) You indeed helped me out... :)
 
Top