Stwest
Stwest

Reputation: 17

Setting up Arrays in one line

Im trying to set up an array with six integer values and one string in one line. I know how to do this one line at a time but cant figure out how to set it up in GameMaker.

array[0] = 10;
array[1] = 1;
array[2] = 5;
array[3] = 12;
array[4] = 12;
array[5] = 3;
array[6] = spr_sprite;

But ideally id like to avoid having multiple lines of code if i can. So how do i set it up in one line?

Upvotes: 0

Views: 1110

Answers (1)

Dmi7ry
Dmi7ry

Reputation: 1777

You can use that extention from the Marketplace (script array_create). Or create it yourself:

/// array_create(value1, value2, ...)
var res;
var n = argument_count - 1;

while (n-- >= 0)
{
    res[n] = argument[n];
}

return res;

Old verisons of GMS may use 16 arguments maximum, but some time ago this limit was removed and now you can use about 700 arguments (actually I don't remember exact value and I guess this may differ on different hardware).

On GMS2 you can initialize arrays using the syntax

var a = [1, 2, 3, 4];

Upvotes: 1

Related Questions