arrays and looping through instances

D

Daz@mbi

Guest
I want to be able to store object variables at the start of a room, so for example when a room loads I want to loop through all coins (that are pre placed in the room editor) and store their x and y in an array.

I know how to use arrays and I know how to use for loops, but I don't know how to loop through each instance of an object.
 

jo-thijs

Member
The with structure loops through every instance of a certain object and makes them execute some code:
Code:
var i = 0;
with obj_coin {
    global.array[i, 1] = y;
    global.array[i, 0] = x;
    i++;
}
EDIT:
Alternatively, you could use instance_find(object_name, iterator).
 
S

Salvakiya

Guest
xstart and ystart? or are you trying to respawn them in the same place after they are destroyed?
 
D

Daz@mbi

Guest
thanks jo-thijs that is what I'm looking for.

salvakiya, I'm not sure how I'm going to do this or if its what I want to do, but the idea is to be able to check if the player has collected the object so that it cant be collected ever again. Once an object is collected it is moved to x = 0 and y = 0 and the array is updated and saved.

I was thinking I could store the object id's but if I decide to add objects later down the track would this screw up the id's?
 
Top