Nested (not chained) accessors result in code error

Answered

Comments

7 comments

  • Russell Kay

    Well from the look of the code above (I have not downloaded the project at all) then _map[? 0 ] would yield the integer 20 which does not have an entry in _map2 at all so it would not work...

    at line 6 the function that you are using returns the value 10 so it would not set entry 20 on the _map2 map.

     

    Russell

    0
    Comment actions Permalink
  • colinator27

    So I just also tested setting that value beforehand, and this code also produces the code error on the last line:

    It should evaluate map1[? 0] to 10, but something seems to go wrong and it doesn't recognize part of it as an accessor.

    0
    Comment actions Permalink
  • John Russell

    Hello! I'm having the exact same issue!

    Nested accessors produce this error: "trying to index a variable which is not an array"

    This code throws the error:

    while(char_seq[| oEmployee.stages_list[| i ]])

    While this does not:

    var stage_number = oEmployee.stages_list[|i]
    while(char_seq[|stage_number])

    So it seems obvious it's a real issue

    1
    Comment actions Permalink
  • Filip Uzunov

    I am hitting the same issue. Following code worked in 2.2 in my project:

    objVikingID.HP = crewHP[?crewNames[|idx]];

    While in 2.3 it throws an error an can be worked arounds as:

    var key = crewNames[|idx];
    objVikingID.HP = crewHP[?crewNames[|idx]];

    0
    Comment actions Permalink
  • Michael McFarlane

    I get this error too!

    I did some testing, and it seems that if you nest 2 (or probably more) data structure accessors e.g,

    outer[? inner[? key]] 

    the compiler misinterprets "outer" as an array, which causes all kinds of whacky errors. In my case, it crashes with an int64 conversion error, because it tries to convert the result of inner[? key] (which is a string) to a number so that it can access the "array" that is "outer", even though outer is not an array.

    The current workaround is to use the actual data structure functions the accessors represent (e.g, ds_map_find_value) or split the nest into multiple lines (as John pointed out), since the compiler cannot misinterpret that.

    EDIT: I just did another test with more nesting, and it seems that every other accessor gets misinterpreted by the compiler as an array accessor (with the innermost being correctly interpreted - then it alternates) - I checked this with the C++ output of the YYC, and it seemed to have half of the required structure access functions, with regular array access in between. (this info is more for the devs, really)

    1
    Comment actions Permalink
  • Filip Uzunov

    Confirming that I too get an int64 conversion error.

    0
    Comment actions Permalink
  • YoYo QA Dept

    Hello,

    I've logged this issue and we will investigate it further.

    Thank you,

    Patrick.

    0
    Comment actions Permalink

Please sign in to leave a comment.