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

GML Array inside map

V

Vitalii Lukyanov

Guest
Hello, I have a problem. I don't know how to access a specific element in the array that is inside of ds_map.
I add coordinates to map like this: "ds_map_add(coords, 1, [533.3, 10456]);" and I want to access to access 1st and 2nd coordinates in array somehow, but I don't understand how to do it, every time I get compilation error or nothing happens. Last time I tried do something like this "ds_list_add(global.pl_instances, instance_create_layer(coords[? i][0], coords[? i][1], "Players", player_blue));" but I get chars_spawn at line 22 : got '[' expected ',' or ')' and chars_spawn at line 22 : wrong number of arguments for function instance_create_layer.
Thanks in advance!

UPD: sadly, now when I use jo-thijs's solution, this array that I try to access is undefined.
UPD2: changed everything to arrays and now it works fine.
 
Last edited by a moderator:

jo-thijs

Member
Hello, I have a problem. I don't know how to access a specific element in the array that is inside of ds_map.
I add coordinates to map like this: "ds_map_add(coords, 1, [533.3, 10456]);" and I want to access to access 1st and 2nd coordinates in array somehow, but I don't understand how to do it, every time I get compilation error or nothing happens. Last time I tried do something like this "ds_list_add(global.pl_instances, instance_create_layer(coords[? i][0], coords[? i][1], "Players", player_blue));" but I get chars_spawn at line 22 : got '[' expected ',' or ')' and chars_spawn at line 22 : wrong number of arguments for function instance_create_layer.
Thanks in advance!
This is an awkward issue in GameMaker that is known for a long time, but still hasn't been solved.

You'll have to do something like this:
Code:
var coord = coords[? i];
ds_list_add(global.pl_instances, instance_create_layer(coord[0], coord[1], "Players", player_blue));
or you can create your own script to deal with arrays in maps.
 
Top