I've been having issues with my code, and so far, no one has been able to help. I am creating a textbox, but when I run the code, it deletes it every time I click the space button and only shows the textbox for a fraction of a second.
From my limited knowledge, I believe the issue is when I tell the program to delete the textbox. Can someone please help and guide me to where I need to fix this issue? This has been a passion project of mine for so long and I would hate to see it destroyed because of one bug.
( My code is below, thank you so much for reading)
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;
//setup
if setup == false
{
setup = true;
draw_set_font(global.font_main)
draw_set_valign(fa_top);
draw_set_halign(fa_left);
// loop through pages
for(var p = 0; p< page_number ; p++)
{
//find how many characters are on the page and store that number in the "text_length" array
text_length[p] = string_length(text[p]);
//get the x postiotion for the textbox
//no character (center the textbox)
text_x_offset[p] = 44;
}
}
//typing the text
if draw_char < text_length[page]
{
draw_char += text_spd;
draw_char = clamp(draw_char, 0, text_length[page]);
}
//flip through pages
if accept_key
{
//if the typing is done
if draw_char == text_length[page]
{
// next page
if page < page_number-1
{
page++;
draw_char = 0;
}
//link text for options
if option_number > 0 {
create_textbox(option_link_id[option_pos]);
}
instance_destroy();
}
}
//if not done typing
else
{
draw_char = text_length[page];
}
//draw the textbox
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 back of the textbox
draw_sprite_ext(txtb_spr, txtb_img, _txtb_x, _txtb_y, textbox_width/txtb_spr_w, textbox_height/txtb_spr_h, 0, c_white, 1);
//options
if draw_char == text_length[page] && page == page_number - 1
{
//option selection
option_pos += keyboard_check_pressed(vk_down) - keyboard_check_pressed(vk_up);
option_pos = clamp(option_pos, 0, option_number-1);
//draw the actions
var op_space = 15;
var _op_bord = 4;
for (var op = 0; op < option_number; op++)
{
//the option box
var _o_w = string_width(option[op]) + _op_bord*2;
draw_sprite_ext(txtb_spr, txtb_img, _txtb_x + 16, _txtb_y - op_space*option_number + op_space*op, _o_w/txtb_spr_w, (op_space-1)/txtb_spr_h, 0, c_white, 1);
//the arrow
if option_pos == op
{
draw_sprite(spr_textbox_indecator, 0, _txtb_x, _txtb_y - op_space*option_number + op_space*op);
}
{
//the option text
draw_text(_txtb_x +16 + _op_bord, _txtb_y - op_space*option_number + op_space*op +2, option[op]);
}
{
{
//draw the text
var _drawtext = string_copy(text[page], 1, draw_char);
draw_text_ext(_txtb_x + border, _txtb_y + border, _drawtext, line_sep, line_width);
}
}
}
}
I have gone on reddit, gamemaker files, and Youtube videos, but noone has yet come up with a solution.