• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ Problem with #

Godelinde

Member
Dear GMS-community,

I'm getting to grips with data_structures and don't understand why scenario A does work and scenario B doesn't.
As far as I can tell only the x and y coördinate for the grid AllAgents have been swapped.
(I prefer to have scenario B.)

Scenario A
GML:
function AddPropertiesToAgentsList(properties){
ds_grid_resize(global.AllAgents, ds_grid_width(global.AllAgents) + 1, ds_grid_height(global.AllAgents));
    for(var i = 0; i < array_length(properties); ++i;) {
    global.AllAgents[# ds_grid_width(global.AllAgents) - 1, i] = properties[i]
    }
}
Scenario B (error: unexpected terminal operator #)

GML:
function AddPropertiesToAgentsList(properties){
ds_grid_resize(global.AllAgents, ds_grid_width(global.AllAgents), ds_grid_height(global.AllAgents) + 1);
    for(var i = 0; i < array_length(properties); ++i;) {
    global.AllAgents[i, # ds_grid_height(global.AllAgents) - 1] = properties[i]
    }
}
Thanks in advance
 

TsukaYuriko

🌠
Forum Staff
Moderator
Put the grid accessor right after the opening bracket. You can't put it in the middle like that.
 

GMWolf

aka fel666
The # belongs to the structure <expr>[# <expr>, <expr>]
Not to the ds_grid_*() call.


The # tells you how to interpret what is on the left of the [ ].
A # means what's on the left is a ds_grid.
A ? Means it's a map, a | a list...
Nothing means it's an array.

This is needed because GM cannot distinguish between different ds_types and you need to tell it explicitly.


So to reiterate, the # symbol is part of the subscript operation ( [# ] ). What you then put inside the [# ] is interpreted as normal, no need for extra # for the x or y argument.
 

TheouAegis

Member
Well, @ can mean it's an array, but typically you don't need to worry about that. And $ in GMS2.3 means it's a struct (in GMS2.2 or older, it means the number on the right is hexadecimal). Dunno if I'm forgetting any other accessors off the top of my head.
 
Top