• 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!

How to create and iterate through an array of instances? [SOLVED]

G

GrayDwarf

Guest
Is it possible to add object instances to an array or perhaps some other way to store a list of instances? I see that I can store enums and other primitive types. I'm working on a block of code that is supposed to return a list of surrounding tiles when given a tile. I was expecting to do something like this:

Code:
/// GetListOfSurroundingTiles(obj_Tile)
tile = argument[0];
var listOfSurroundingTiles;
var i = 0;
with(obj_Tile)
{
    if (self.id == tile.id)
    {
        continue;
    }

    if (...)
    {
        if (...)
        {

            listOfSurroundingTiles[i++] = self
        }
    }
}

return listOfSurroundingTiles;
 
G

GrayDwarf

Guest
Misunderstanding of "self" really screwed me up because things appear to work when using self but they aren't or at least not the way you would expect (without knowing better).

I realize now that making a call to a script like this from a mouse event does not pass in the instance but instead passes in "self", literally.

For anyone else coming across this issue, per documentation:
"self can be used to identify the calling instance of the current block of code. It always returns the value of -1 which GameMaker: Studio interprets as the unique ID for the instance. In general you should never need to use this keyword, as you can do the same task more efficiently and appropriately using other keywords or functions, and is maintained for legacy support reasons. "
 
Top