Array with multiple properties

P

PabloMagno

Guest
My issue is really simple, i'm trying to do this in a "Create" event:

Code:
coords[1,1].property = "SAMPLE";
So, I'm expecting that if I do:

Code:
test = object.coords[1,1].property;
I'll get "SAMPLE" loaded in test (If an instance "object" is created).

But I get:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_standard_board:

trying to index a variable which is not an array
at gml_Object_obj_standard_board_Create_0 (line 11) - coords[1,1].property = "SAMPLE";
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_standard_board_Create_0 (line 11)
called from - gml_Script_create_board (line 6) - created_board = instance_create_layer(0, 0, "Board", board_type);
called from - gml_Room_match_Create (line 9) - board = create_board (obj_standard_board)
Well, so "trying to index a variable which is not an array"... Of course the problem is the mix of the "dot notation" after the "[ ]" notation. But why? Any workaround?



Thanks in advance,


Pablo.
 

TheouAegis

Member
Surround it with parentheses.

But are you sure you don't have a variable called coords anywhere else? Did you make a globalvar coords? Do you yave a var coords? Do you set coords=0? Any of those will make coords a normal variable even though it was created as an array.
 

Smiechu

Member
What are you trying to do?

The notation:
coords[1,1].property = "SAMPLE";
Means -> change the variable "property" in instance id stored in array "coords" at indexes 1,1...
If you don't have an array coords before it will not create one.

If your migrating from other language, please take the time and learn the characteristic of GML language first.
The code with two dots is also not possible in gml.
 
P

PabloMagno

Guest
Surround it with parentheses.

But are you sure you don't have a variable called coords anywhere else? Did you make a globalvar coords? Do you yave a var coords? Do you set coords=0? Any of those will make coords a normal variable even though it was created as an array.
Thanks, I'll try it and let you know. No, coords is a property of the class, no a global declarated variable.

What are you trying to do?

The notation:
coords[1,1].property = "SAMPLE";
Means -> change the variable "property" in instance id stored in array "coords" at indexes 1,1...
If you don't have an array coords before it will not create one.

If your migrating from other language, please take the time and learn the characteristic of GML language first.
The code with two dots is also not possible in gml.
So in this case, I could initialize by using an instance_create from a class with the property "property" before (i think).


I'll try with all your suggestions. Thanks to both of you!
 
P

PabloMagno

Guest
Thanks, I'll try it and let you know. No, coords is a property of the class, no a global declarated variable.



So in this case, I could initialize by using an instance_create from a class with the property "property" before (i think).


I'll try with all your suggestions. Thanks to both of you!
I finally used this workaroud
 
Top