JJSBlog

When 140 characters won't do.

GameMaker Arrays

- Posted in Uncategorized by

So I wanted to continue working on the system of different asteroids for different sizes. My thought is I'll have an array (or series of parallel arrays) which will have information like minimum mass, maximum mass, sprite used, name of object. Then given a certain mass it can pick only from valid options. Both a minimum and maximum are because I figure it's more interesting if there's some overlap between types of objects, rather than a flat cutoff. Or it could even be possible to have rare objects that only exist in a very narrow range. Whatever. But before doing this I needed to see how arrays work in GameMaker, and it seems... kind of stupid. More a pain to use than in other languages I've dealt with.

Thing 1: Initializing arrays. In some languages, you can just give a specific size for an array. In other languages, it doesn't set limits, and you can even use words as keys for the array rather than just a series of integers. In GML, you need to initialize every spot in the array similar to declaring a variable, before the program is allowed to do anything with it. Like for Zenzenzen purposes if I wanted to keep track of the last 10 asteroids I merged with for whatever reason, I'd first have to do some sort of loop and set lastmerged[i]=0 as a default value or whatever.

Thing 2: Initializing the data in arrays. In PHP which I've used the most in recent years, if I want to set up an array with multiple values it can be as simple as $Names = array("Josh", "Zach", "Austin", "Luke"). In GML that isn't done. I'd need to have a line for name[0] = "Josh"; and another for every other value. It seems like unless you're dealing with a very small set of data it will be the sensible thing to set up a file with the data (or a string which can be made to be treated like a file) and read that into an array with a loop.

Comments