A probelm with arrays

Resolved

game maker tells me that I am
"trying to index a variable which is not an array"
but I don't seem to understand what makes my beloved variable distanceprojection a non-array. A picture is a good way to show my problem:

http://i.imgur.com/8EzzzJY.png

where did I go wrong? What could cause distanceprojection to not be considered an array?

Posted Sep 23, 2016, 12:43 PM UTC

36
TheAppleBOOM•

Somewhat related, it seems like GML cleans up arrays before the On Destroy event is called, so make sure you deal with them before that.

2
GrroxRogue•

you should post the create event code where you make the variabe

1
microCACTUSOP•

as you can see from the image (the very first line under "Search Context") it's merely

    globalvar distanceprojection;

and nothing else. Should it be something like

    globalvar distanceprojection[200,3];

or was my version enough? Or did I make some other mistake?

1
GrroxRogue•

pretty sure you have to declare that a variable should be an array by doing something like

array[0]=0;

when you create it. I think as long as you initialize one "spot" in the array you can just add more values in later spots whenever... but it's been a while since i messed around with arrays since DS's are much more convenient... Actually I seem to remember it being bad practice to not initialize the array to as many positions as you will need because when you go over the initialized positions it copies the array and makes a new one or something so it takes extra power... not sure tho.

3
microCACTUSOP•

I was completely unfamiliar with the concept of "initializing arrays", thank you, it seems like it worked (not sure yet because the rest of the code is a mess).
I'll mark this as "solved" anyway.
Thanks again.

2
Macskalacs•

Well I can't find anything on google if you can make an array global.

1