Object keeps respawning

I got a textbox system here, but I got a problem that when the textbox destroys itself, it creates itself again due to this in the step event of the person I'm talking to:
(KeyInteract = vk_space)

GML:
if(!instance_exists(obj_textbox)){
    if(place_meeting(x, y, obj_player)){
        if(obj_player.KeyInteract){
            obj_player.isInteracting = true;
            instance_create_layer(0, 0, "TextboxLayer", obj_textbox);
            obj_textbox.message = myMsg;
        }
    }
}

Here's the textbox create, step & draw event:

Create:
Code:
boxWidth = sprite_get_width(spr_textbox);
page = 0;
player = obj_player;
charCount = 0;

message = "ERROR";
Step:
Code:
if(keyboard_check_pressed(vk_space)){
    if(page + 1 < array_length_1d(message)){
        page += 1;
        charCount = 0;
    }else{
        instance_destroy(obj_textbox);
        charCount = 0;
        obj_player.isInteracting = false;
    }
}
Draw:
Code:
draw_sprite(spr_textbox, 0, 0, 550);

draw_set_font(fnt_NPC);
draw_set_color(c_black);
           
//Draw Text
charCount += 1;
textPart = string_copy(message[page], 1, charCount);
draw_text_ext(10, 550, textPart, 32, boxWidth);
draw_set_color(c_white);
draw_text(63, 143, string(page));
 
Last edited:

Nidoking

Member
If you want something not to happen, set a variable telling it when to happen or when not to happen and check it before doing the thing.
 
Top