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

Rob

Member
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.
 

Attachments

Last edited:
D

DekuNut

Guest
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?
 

FredFredrickson

Artist, designer, & developer
GMC Elder
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.
 
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.
 

Rob

Member
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:

Rob

Member
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.
 
Top