GML ds_map Accessor in Multidimensional Array

D

DarthTenebris

Guest
Hello everybody,

As the title says, I have an array containing a bunch of maps and an extra:
Code:
for (var i = 0; i < 5; i++) {
     for (var j = 0; j < 5; j++) {
          playerInventory[i, j] = ds_map_create();
     }
}
mouseInventory = ds_map_create();
I'm trying to check whether the key "id" in both maps are the same:
Code:
for (var i = 0; i < 5; i++) {
     for (var j = 0; j < 5; j++) {
          if (playerInventory[i, j][? "id"] == mouseInventory[? "id]) {
               doSomething();
          }
     }
}
Unfortunately the compiler doesn't like that, saying:
got '[?' expected ')'
malformed assignment
However, if I replace the accessor with ds_map_find_value(), the compiler is perfectly happy with it:
Code:
if (ds_map_find_value(playerInventory[i, j], "id") == mouseInventory[? "id"]) {
     doSomething();
}
Have I done something dumb again or have I found a bug?

Thank you for your time.
 

chamaeleon

Member
Hello everybody,

As the title says, I have an array containing a bunch of maps and an extra:
Code:
for (var i = 0; i < 5; i++) {
     for (var j = 0; j < 5; j++) {
          playerInventory[i, j] = ds_map_create();
     }
}
mouseInventory = ds_map_create();
I'm trying to check whether the key "id" in both maps are the same:
Code:
for (var i = 0; i < 5; i++) {
     for (var j = 0; j < 5; j++) {
          if (playerInventory[i, j][? "id"] == mouseInventory[? "id]) {
               doSomething();
          }
     }
}
Unfortunately the compiler doesn't like that, saying:

However, if I replace the accessor with ds_map_find_value(), the compiler is perfectly happy with it:
Code:
if (ds_map_find_value(playerInventory[i, j], "id") == mouseInventory[? "id"]) {
     doSomething();
}
Have I done something dumb again or have I found a bug?

Thank you for your time.
GMS does not currently support chaining accessors using variable[...][...]. You need to treat each access separately, and either store the value for each level in a local variable, or use it as an argument to a function like you do with ds_map_find_value().
 

Yal

šŸ§ *penguin noises*
GMC Elder
I'm pretty sure chaining like OP is trying to do is confirmed to be a feature in the 2.3 update, so whenever that rolls around this'll just work. Unfortunately, the release date isn't revealed yet.
 
D

DarthTenebris

Guest
GMS does not currently support chaining accessors using variable[...][...]. You need to treat each access separately, and either store the value for each level in a local variable, or use it as an argument to a function like you do with ds_map_find_value().
Ah alright. I forgot about that. I knew arrays can't be chained, but chaning accessors is not heard of as much.
I'm pretty sure chaining like OP is trying to do is confirmed to be a feature in the 2.3 update, so whenever that rolls around this'll just work. Unfortunately, the release date isn't revealed yet.
Nice to see it being planned anyway :)
 
Top