GML GMS 1.4 - trying to index a variable which is not an array

bazza0853

Member
GML:
// this is the npc index. Ex. 0 is sam, 1 is Rachel etc..
var n = 0;

// text that pops on textbox
npc[n,story[0]] = "Hi"              ;
npc[n,story[1]] = "My name is Sam"    ;
npc[n,story[2]] = "How are you?"    ;
npc[n,story[3]] = "That's good."      ;

//choices below the text
npc[n,choice[0,0]] = "Hello"        ;
npc[n,choice[0,1]] = "Hi"            ;
npc[n,choice[1,0]] = "Good to know" ;
npc[n,choice[1,1]] = ""             ;
npc[n,choice[2,0]] = "I'm quite ok" ;
npc[n,choice[2,1]] = "Not so good"  ;
npc[n,choice[3,0]] = "Exit"           ;
npc[n,choice[3,1]] = ""             ;

// move to next story(text), -2 for closing textbox
npc[n,path[0,0]] = 1;
npc[n,path[0,1]] = 1;
npc[n,path[1,0]] = 2;
npc[n,path[1,1]] = 2;
npc[n,path[2,0]] = 3;
npc[n,path[2,1]] = 3;
npc[n,path[3,0]] = -2;
npc[n,path[3,1]] = -2;
I'm getting this error on my compiler..
trying to index a variable which is not an array
at gml_Object_obj_npc_CreateEvent_1 (line 9) - npc[n,story[0]] = "Hi"
I thought I'm allowed to use arrays inside arrays?
why am i getting this error? also would this be the best way to implement textbox system ?
 

chamaeleon

Member
Is story, choice, and path declared as arrays with values filled in that makes sense to use as secondary, non-overlapping, indices into npc?
 

bazza0853

Member
Is story, choice, and path declared as arrays with values filled in that makes sense to use as secondary, non-overlapping, indices into npc?

I'm sorry I don't quite understand your answer as i'm not that good in english
I haven't declared story, choice, and path
so all I have to do is
story[0] = 0;
story[1] = 0;
and so on ?

choice[0,0] = 0;
choice[0,1] = 0;
choice[1,0] = 0;
choice[1,1] = 0;
...
...
 

chamaeleon

Member
I'm sorry I don't quite understand your answer as i'm not that good in english
I haven't declared story, choice, and path
so all I have to do is
story[0] = 0;
story[1] = 0;
and so on ?

choice[0,0] = 0;
choice[0,1] = 0;
choice[1,0] = 0;
choice[1,1] = 0;
...
...
And if you were to have these lines, what do you think the difference is between npc[n, story[0]] and npc[n, choice[0, 0]]? There is none, both is the same as writing npc[n, 0], assuming those are the values assigned in story and choice. You are not storing those arrays within npc. You are using their values as indices. If you want to assign something to an array, as you do, you need to have that value on the right hand side of the equal sign.

You might be looking for something along the lines of
GML:
story[0] = "Hi"              ;
story[1] = "My name is Sam"    ;
story[2] = "How are you?"    ;
story[3] = "That's good."      ;
choice[0,0] = "Hello"        ;
choice[0,1] = "Hi"            ;
...
path[0,0] = 1;
path[0,1] = 1;
...
npc[n, 0] = story;
npc[n, 1] = choice;
npc[n, 2] = path;
 
Last edited:

bazza0853

Member
I was getting a bit confused when I was writing the last reply, but wow after the correction you gave me it works perfect and I understand the concept of arrays much better now, thanks a lot !!!
 
Top