1
\$\begingroup\$

Arrays in Gamemaker Studio seems to not need to have its size be declared, and infact it doesn't seem to be possible to declare a finite array.

Instead, it seems it just keeps indexing for each declaration....at least as far as I can tell. Obviously, this is limited by memory, I would presume.

Question: So, can I have a loop that says something like array[i] = 0, while increasing i for each loop through?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

It seems that after 32767 the engine will have undefined behavior. This is stated at the return length array function. Game Maker reference

However, if you ever go higher than 1000 in a array you're using it wrong.

Another important note is that when you assign a index that doesn't exist before, it will allocate memory up to that index, so it would be best if you assign first the highest value you need and then count down to zero.

\$\endgroup\$
4
  • \$\begingroup\$ Ah, that's useful. Thanks. So, just how inefficient is the assigning process, when you do actually do it going upwards? For instance, in cases where you don't neccesarily know how large you need the array to be when you launch the program. \$\endgroup\$ Commented Jun 14, 2016 at 13:52
  • \$\begingroup\$ @SangoProductions Doing it once per frame/step is enough to see some overhead in medium sized game. Doing it multiples times in a single frame/step can cause some sttutering(a player noticing that a frame took too long). I recommend to allocate the minimum, or to use another form of data structure(like stacks). \$\endgroup\$
    – DH.
    Commented Jun 14, 2016 at 16:01
  • \$\begingroup\$ Oh right! Stacks! Those are a thing. Not to mention incredibly convenient for my uses. Was only going to update at maximum once every couple of left mouse clicks. Thanks for the information. Time to read up on Stacks. \$\endgroup\$ Commented Jun 14, 2016 at 16:22
  • \$\begingroup\$ @SangoProductions There's also queues. They are called ds_stack and ds_queue inside GML, if you look for further reference. \$\endgroup\$
    – DH.
    Commented Jun 14, 2016 at 22:18
1
\$\begingroup\$

Yes they are not finite and you can not set a size. So if you wan't to have an finite array you'll have to set a size in another variable

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .