SOLVED Textbox aborting everytime

libragenmu

Member
So i'm trying to create a RPG textbox just to show some messages and when u press space it goes to the next page(text).
But everytime it aborts in 2 cases:

First is when it says that i haven't set the variable when i did in a FOR inside an IF before.

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object obj_textbox:

Variable obj_textbox.text_x_offset(100025, 0) not set before reading it.
 at gml_Object_obj_textbox_Draw_0 (line 72) -        draw_sprite_ext(txtb_spr, txtb_img, textbox_x + text_x_offset[page], textbox_y, textbox_width/txtb_spr_w, textbox_height/txtb_spr_h, 0, c_white, 1);
############################################################################################
gml_Object_obj_textbox_Draw_0 (line 72)
And second it says that the value is undefined but i set the value of the var before.

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object obj_textbox:

DoSub :2: undefined value
 at gml_Object_obj_textbox_Draw_0 (line 45) -                                    if page < page_number-1
############################################################################################
gml_Object_obj_textbox_Draw_0 (line 45)
So theses are my codes:

Create:
Code:
depth = -9999;


//txtbox  parametros
textbox_width = 144
textbox_height = 64;
border = 8;
line_sep = 12;
line_width = textbox_width - border * 2
txtb_spr = spr_menu;
txtb_img = 0;
txtb_img_spd = 6/60;
//text_x_offset[0] = 0;
//texto

page = 0;
page_number = 0;
text_x_offset[0] = page;    
text[0] = "Ola meu compatriota";
text[1] = "Hoje eh um belo dia para se ter OI ecaaa";
text[2] = "Love live nijigasaki eh o melhor LL(pena que n me deixam pegar nada # titi)";
text[3] = "sla ultimo texto de teste :juan:";

text_length[0]  = string_length(text[0]);
draw_char = 0;
text_spd = 1;

setup = false;

And the Draw:
Code:
 accept_key =    keyboard_check_pressed(vk_space);
 
 textbox_x = camera_get_view_x(view_camera[0]);
  textbox_y = camera_get_view_y(view_camera[0]) + 144;

if setup == false
    {
        setup = true;
        draw_set_font(Font1);
        draw_set_valign(fa_top);
        draw_set_halign(fa_left);
        
        //loop paginas
        page_number =  array_length(text[0]);
        for(var p = 0; p < page_number; p++)
            {
                
                //numero de letras na pagina e guarda no array
                text_length[p] = string_length(text[p]);
                
                
                //x da textbox
                    //sem letras/caracteres (center textbox    )
                text_x_offset[p] = 44;
                
            }

    }

//digitar

    if draw_char < text_length[page]
        {
            draw_char += text_spd;
            draw_char = clamp(draw_char, 0, text_length[page]);
        }
        
//flip paginas
    if accept_key 
        {
            //if  digitacao concluida
            if draw_char == text_length[page]
                {
                    //next page
                    if page < page_number-1
                        {
                            page++;
                            draw_char = 0;
                        
                        }
                    //destroi a txtbox
                    else
                        {
                            instance_destroy();
                        }
                }
            //if digitacao não concluida
            else
                {
                    draw_char = text_length[page];
                }
        
        }
        
//draw the textbox
txtb_img += txtb_img_spd;
txtb_spr_w = sprite_get_width(txtb_spr);
txtb_spr_h = sprite_get_height(txtb_spr);

//back txtbox

    draw_sprite_ext(txtb_spr, txtb_img, textbox_x + text_x_offset[page], textbox_y, textbox_width/txtb_spr_w, textbox_height/txtb_spr_h, 0, c_white, 1);
    
//draw text

    var _drawtext = string_copy(text[page], 1, draw_char);
    draw_text_ext(textbox_x + text_x_offset[page] + border, textbox_y + border, _drawtext, line_sep, line_width);
P.S: my version is v2.3.4.580
 
Top