Array with multiple properties

Discussion in 'Programming' started by PabloMagno, Aug 9, 2018.

  1. PabloMagno

    PabloMagno Member

    Joined:
    Sep 13, 2017
    Posts:
    14
    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:

    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.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,889
    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.
     
  3. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    626
    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.
     
  4. PabloMagno

    PabloMagno Member

    Joined:
    Sep 13, 2017
    Posts:
    14
    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!
     
  5. PabloMagno

    PabloMagno Member

    Joined:
    Sep 13, 2017
    Posts:
    14
    I finally used this workaroud
     
  6. MarisFrance

    MarisFrance Member

    Joined:
    Jul 26, 2018
    Posts:
    22
    For myself I added Lua extension.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice