Error in code

R

Rheano

Guest
20210120_184059.png20210120_184039.png

20210120_184039.png
To elaborate on the issue I am following a text box tutorial and have run into this error and I believe it's to do with [Page] although when the other person you're paid this tutorial did it seemed to go find for them


I've been told it's because I tried to access text as an 'array' but I have no idea on how to fix upon this
Game maker 2.31
 

chamaeleon

Member
It would be a good idea showing any code at all that shows how you assign anything to text or modify its content.
 

samspade

Member
There's not enough information to say for sure, but I would always start with the assumption that the error message is correct. In this case, it is saying that you are trying to use a variable as an array, which is not an array. Specifically the text variable. You are indeed using text as an array—that's what using the brackets does. There's no way to know from this end what value text is, but I would assume that it is not an array. It seems like it is supposed to be an array, so looking at all prior places where you create or assign variables to text would be good place to start debugging.
 

chamaeleon

Member
So text is a string, not an array, while myText is an array. Perhaps you intended to use myText in the draw text call.

Edit: Different object between the two variables. So, either make text an array, or if it's only supposed to be a single string, get rid of the page array indexing part. All depends on what you actually want to implement, and you better have a good idea what that is, and not stumble in the dark throwing things at the wall and see what sticks.
 
R

Rheano

Guest
So in the tutorial it states

:"so we want to print a spesific page, whatever page that we're on so if we just put;;
text[0] it will only print the first page but I basically want to change this when I press space.

So we need this to be varible that we can alter so i'm going to make this "page"

And then in the create event she adds

page = 0; as this will be the first entry
 

chamaeleon

Member
So in the tutorial it states

:"so we want to print a spesific page, whatever page that we're on so if we just put;;
text[0] it will only print the first page but I basically want to change this when I press space.

So we need this to be varible that we can alter so i'm going to make this "page"

And then in the create event she adds

page = 0; as this will be the first entry
But
GML:
text = "example";
is not something that has "pages". It's just a single string. If you want pages, aka multiple strings, use the array declaration like you have for the npc.
 
R

Rheano

Guest
So text is a string, not an array, while myText is an array. Perhaps you intended to use myText in the draw text call.

Edit: Different object between the two variables. So, either make text an array, or if it's only supposed to be a single string, get rid of the page array indexing part. All depends on what you actually want to implement, and you better have a good idea what that is, and not stumble in the dark throwing things at the wall and see what sticks.
So in the tutorial it states

:"so we want to print a spesific page, whatever page that we're on so if we just put;;
text[0] it will only print the first page but I basically want to change this when I press space.

So we need this to be varible that we can alter so i'm going to make this "page"

And then in the create event she adds

page = 0; as this will be the first entry
But
GML:
text = "example";
is not something that has "pages". It's just a single string. If you want pages, aka multiple strings, use the array declaration like you have for the npc.
So I tried to add in something additional which was

Page +=1;
If(page+1< array_length_d(text)){
page+= 1;
}

It seemed to continue with the error what do you suggest I input for the array decleration?
 

samspade

Member
If you watch the tutorial, when she creates a text box, she overwrites the text variable with the my_text variable from the other object, in that object the variable is an array. Is this the same in yours? It looks similar, but you might want to step through it in the debugger to find out what is happening. For example, perhaps you are creating a text box in some other way, so it is using the default variable for text which is just a string. Or perhaps something is overwriting your code.
 

chamaeleon

Member
Good call, @samspade, The textbox is generic, and is populated by content held in other instances as needed, presumably.

For the text box to work "on its own" for testing purposes, perhaps, just make its own initialization an array.
GML:
text = ["example"];
or a bit more verbose
GML:
text = [];
text[0] = "example";
 
Top