GMS 2.3+ Struugle to fix some glitch in my code

Kakkiak

Member
so i'm following a tuto ! and i'm stuck at a dialogue box episode ! and i tried to fix the error but i'm to new to this and i don't know where the error is ! if you could help me it would mean a lot to me !

so the error is :


local variable _txtb_x(100067) not set before reading it.

at gml_Object_Obj_textbox_Draw_0 (line 94) - draw_sprite_ext(txtb_spr, txtb_img, _txtb_x, _txtb_y, Textboxwidth/txtb_spr_w, Textboxheight/txtb_spr_h, 0, c_white, 1);


and around the line is that


var _txtb_x = textbox_x + text_x_offset[page];

var _txtb_y = textbox_y;

txtb_img += txtb_img_spd;

txtb_spr_w = sprite_get_width(txtb_spr);

txtb_spr_h = sprite_get_height(txtb_spr)

draw_sprite_ext(txtb_spr, txtb_img, _txtb_x, _txtb_y, Textboxwidth/txtb_spr_w, Textboxheight/txtb_spr_h, 0, c_white, 1); <- line 94


if somone could help me it would mean a lot !
 

FrostyCat

Member
Is that var _txtb_x line in a different event, or hidden behind a conditional that the draw_sprite_ext line isn't also in?
 

Kakkiak

Member
Soo i guess this glitch is fixed but now i've got an another one with that error

Push :: Execution Error - Variable Index [1] out of range [1] - -1.char(100042,1)
at gml_Object_Obj_textbox_Draw_0 (line 57) - var _current_txt_w = string_width ( _txt_up_to_char ) - string_width( char[c, p] );
to that code


char [c, p] = string_char_at (text[p], _char_pos);

var _txt_up_to_char = string_copy( text[p], 1, _char_pos);
var _current_txt_w = string_width ( _txt_up_to_char ) - string_width( char [c, p]);

if char[c, p] == " " {last_free_space = _char_pos+1 };


if _current_txt_w - line_break_offset[p] > line_width
{
line_break_pos[ line_break_num[p], p] = last_free_space;
line_break_num[p]++;
var _txt_up_to_last_space = string_copy( text[p], 1, last_free_space);
var _last_free_space_string = string_char_at(text[p], last_free_space);
line_break_offset[p] = string_width(_txt_up_to_last_space ) - string_width( _last_free_space_string );
}

for (var c = 0; c < text_lenght[p]; c++)
{

var _char_pos = c+1;
var _txt_x = textbox_x + text_x_offset[p] + border;
var _txt_y = textbox_y + border;

var _txt_up_to_char = string_copy( text[p], 1, _char_pos);
var _current_txt_w = string_width ( _txt_up_to_char ) - string_width( char[c, p] ); <- line 57

var _txt_line = 0;

for (var lb = 0; lb < line_break_num[p]; lb++)
{
if _char_pos >= line_break_pos[lb, p]
{
var _str_copy = string_copy( text[p], line_break_pos[lb, p], _char_pos-line_break_pos[lb, p] );
_current_txt_w = string_width(_str_copy) ;

_txt_line = lb+1;
}
}

char_x[c, p] = _txt_x + _current_txt_w;
char_y[c, p] = _txt_y + _txt_line*line_sep
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Arrays are 0-based. You are trying to access element 1 of an array that has a size of 1. Therefore, that array has an element 0, but no element 1.
 

Nidoking

Member
I see you using the variables c and p before you've defined the local variable c. Is there a local c and an instance c?
 

Kakkiak

Member
I see you using the variables c and p before you've defined the local variable c. Is there a local c and an instance c?
are you talking about something like that ?

for(var p = 0; p < page_number; p++)
{

text_lenght[p] = string_length(text[p]);



text_x_offset[p] = 0;


for (var c =0; c < text_lenght[p]; c++)
 

Nidoking

Member
I'm talking about this

char [c, p] = string_char_at (text[p], _char_pos);
followed by this

for (var c = 0; c < text_lenght[p]; c++)
The first c is clearly not the second c, because you haven't defined it yet. So it's defined as something else before this, and that definition is going to conflict with the definition you have here. Don't let two variables with the same name exist in overlapping scopes.
 
Top