• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Textbox disappear???

Reddoka

Member
I wrote the following code to create the queuing text boxes like the tutorial, but then when I started running the game the textbox didn't appear. Can anyone help me ??? Thanks a lot! <3

Here's the code of Newtextbox's script:

GML:
var _obj
if (instance_exists(oText)) _obj = oTextQ; else _obj = oText;
with (instance_create_layer(0,0,"Instances",_obj))
{
    message = argument[0];
    if (instance_exists(other)) originInstance = other.id else originInstance = noone;
    if (argument_count > 1) background = argument[1]; else background = 1;
}
The object oText's Step event:

Code:
lerpProgress += (1 - lerpProgress) / 50;
textProgress += global.textSpeed;

x1 = lerp(x1,x1Target,lerpProgress);
x2 = lerp(x2,x2Target,lerpProgress);

if (mouse_check_button(mb_left) or keyboard_check_pressed(vk_space))
{
    var _messageLength = string_length(message);
    if (textProgress >= _messageLength)
    {
        instance_destroy();
        if (instance_exists(oTextQ))
        {
            with (oTextQ) ticket--;
        }
    }
    else
    {
        if (textProgress > 2)
        {
            textProgress = _messageLength;
        }
    }
}
The object oTextQ's Create event:

GML:
ticket = instance_number(oTextQ);
And its Step event:

Code:
if (ticket == 0)
{
    instance_change(oText, true);
}
Finally, the object oGame's Left down event:


GML:
Newtextbox("Text text text");
Newtextbox("Text text more text")
 

Yal

šŸ§ *penguin noises*
GMC Elder
Code:
if (textProgress >= _messageLength)
{
   instance_destroy();
The textbox instantly destroys itself once it has fully printed the message, instead of waiting for a key press. This might make it disappear before you get a chance to see it.

...which happens really soon, since you set it to message length if the mouse is held down or space is pressed with a specific timing.
Code:
    else
    {
        if (textProgress > 2)
        {
            textProgress = _messageLength;
        }
    }
background = 1
Using numbers instead of asset IDs is deprecated, the IDs can change every time you compile the game. Use the resource name (without quotes) instead.

What is in the Draw event? If the text box object doesn't draw a text box, you can't see it.
 

Imperial

Member
I always use this Textbox code in games

First You need to declare this global variable at the start of the game

GML:
global.messages_queue = ds_queue_create();
and then make a textbox object and import any textbox sprite you want (spr_textbox)

and don't forget to make a font for the textbox

GML:
//Create Event
image_speed = 0.05;
drawstr = "";
pos = 0;

//Step Event
if(!ds_queue_empty(global.messages_queue))
{
    drawstr = ds_queue_head(global.messages_queue);
}
else
{
    drawstr = "";
}

if(drawstr != "")
{
    visible = 1;
}
else
{
    visible = 0;
}

//Draw GUI Event
var yy1 = display_get_gui_height() - sprite_get_height(spr_textbox);
draw_sprite(spr_textbox,0,0,yy1);

if(drawstr != "")
{
    draw_set_font(font_textbox);
    draw_set_color(c_white);
    cstr = string_copy(drawstr,1,pos);
    draw_text_ext_transformed(16,yy1+16,cstr,-1,-1,1,1,0);
    pos += 1.5;
}

if(drawstr != "" && pos < string_length(drawstr))
{
    audio_play_sound(snd_type,100,false); //This is an optional typing sound effect
}

//Enter Key Pressed Event
if(!ds_queue_empty(global.messages_queue))
{
    if(pos > string_length(drawstr))
    {
        audio_play_sound(snd_click,100,false); //This is an optional click sound effect
        ds_queue_dequeue(global.messages_queue);
        pos = 0;
    }
}
else
{
    pos = string_length(drawstr);
}
All the last thing you need to do is to make a create_message script (function in 2.3)

GML:
ds_queue_enqueue(global.messages_queue,argument0);
and don't forget to place the Textbox object anywhere in the room
 
Top