FATAL ERROR: Trying to index a variable which is not an array

Discussion in 'Programming' started by Rob, Jul 12, 2016.

  1. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    681
    Using GM:proffessional, no tag for it that I can find.

    Hello, I have a bug I can't seem to fix. The array is initialised properly and only recently, the last few days there is this fatal error.

    The bug I can't fix is as follows:


    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Draw Event
    for object obj_slime_farm:
    trying to index a variable which is not an array
    at gml_Object_obj_slime_farm_DrawEvent_1 (line 8) - if global.a_stats_pl[0, 48] >= global.a_stats_pl[0, 49]{
    ############################################################################################

    global.a_stats_pl is defined in obj_stats create event which initialises all the games arrays.

    Initialisation of arrays looks like this:

    global.a_stats_pl[0, 1] = 10;
    global.a_stats_pl[0, 2] = 50;

    and sometimes this:

    for (var t = 0; t < 99; t += 1){
    global.a_array[0, t] = -1;
    }

    These are the only ways i'm setting up arrays and the only time I've had a similar error before is if i've made a typing mistake. I've checked obj_stats as well as the code where the error appears, copy pasted etc and still haven't fixed the bug.

    Any pointers as to where I could look or what might be causing the issue would be greatly appreciated.

    Thank you.

    PS Attached some screenshots if it helps.
     

    Attached Files:

    Last edited: Jul 12, 2016
  2. DekuNut

    DekuNut Member

    Joined:
    Jun 29, 2016
    Posts:
    40
    I use studio, so not sure if things are different in professional. The problem is obviously something to do with a value in the global.a_stats_pl array.

    Can you post the code you used to initialize global.a_stats_pl?
     
  3. FredFredrickson

    FredFredrickson Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    118
    I guess a simple question would be... did you initialize your array to have values at [0, 48] and [0, 49] prior to trying to use it?

    If you only initialize global.a_stats_pl to have two values, as you did above, you're going to error if you check [0, 48] or [0, 49]. Those are two different arrays you've mentioned too.
     
  4. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,163
    I would double check that the array is actually initialized before being indexed.

    Another thing you should check is that you aren't accidentally assigning something other than an array to that variable at any point. Search for all instances of that variable name in your code to be sure.
     
  5. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    681
    Thanks for your replies. I could post the whole code for the array. For those two specific entries it's this:
    global.a_stats_pl[0, 48] = 1;
    global.a_stats_pl[0, 49] = 100;

    The examples I gave in the first post are just to show how I setup arrays in general. There's quite a few different ones but I set them up in the same way.

    I think it's more likely to be what flying saucer invasion has suggested. How would I of assigned something else to the array? I'm not home at the moment but I'll post code of how I'm assigning values at initialisation and during the game run I f to give you guys more of an idea. Thanks.
     
    Last edited: Jul 13, 2016
  6. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    681
    Ugh... I must of looked at this script a dozen times last night and my eyes glossed over the obvious mistake:

    ///scr_lose_stam();
    global.a_stats_pl[0,61] -= global.tr_stam_cost;
    if global.a_stats_pl[0,61] < 0{
    global.a_stats_pl = 0;
    }

    I kept checking this script because the error only occurred when the slime's stamina(global.a_stats_pl[0,61]) was 0.

    The slime trains, and uses stamina and calls the above script.

    Thanks for your input people.
     

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