• 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!

Legacy GM need help on alarm on textbox! (in obj_textbox)

E

EZTALES

Guest
hey yall,
was wondering how to make this textbox appear when you press a button (Z), and only alowing it once at a time so you can't spam. i was thinking about an alarm but dont know how. help?
code here:
Code:
CREATE:
showtext =0;
STEP:

if (place_meeting(x,y,obj_player)) && (keyboard_check(ord("Z")))
{
    showtext = 1;
}
else
{
    showtext = 0;
}
DRAW:
draw_self();

if (showtext == 1)
{
    draw_set_color(c_blue);
    draw_set_halign(fa_center);
    draw_set_font(fnt_textbox_normal);
    draw_text(x,y-30," Its your# bookshelf. ")
}
thanks anyone!
 

Relic

Member
Instead of keyboard_check try using keyboard_check_pressed - so the code inside the IF block only runs on the step that the Z key was first pressed, not every step. You would probably want your showtext variable to toggle between 1 and 0 every Z press rather than being “else showtext=0” when the player did not press Z this step.
 

PlayerOne

Member
hey yall,
was wondering how to make this textbox appear when you press a button (Z), and only alowing it once at a time so you can't spam. i was thinking about an alarm but dont know how. help?
code here:
Code:
CREATE:
showtext =0;
STEP:

if (place_meeting(x,y,obj_player)) && (keyboard_check(ord("Z")))
{
    showtext = 1;
}
else
{
    showtext = 0;
}
DRAW:
draw_self();

if (showtext == 1)
{
    draw_set_color(c_blue);
    draw_set_halign(fa_center);
    draw_set_font(fnt_textbox_normal);
    draw_text(x,y-30," Its your# bookshelf. ")
}
thanks anyone!

Instead of an if else use a true/false check for the text box and using keyboard_check_pressed as @Relic suggested.

Code:
CREATE:
showtext =false;

STEP:
if (place_meeting(x,y,obj_player) && keyboard_check_pressed(ord("Z")))
{
   showtext=!showtext
}

DRAW:
draw_self();

if (showtext == true)
{
   draw_set_color(c_blue);
   draw_set_halign(fa_center);
   draw_set_font(fnt_textbox_normal);
   draw_text(x,y-30," Its your# bookshelf. ")
}
 
E

EZTALES

Guest
Instead of an if else use a true/false check for the text box and using keyboard_check_pressed as @Relic suggested.

Code:
CREATE:
showtext =false;

STEP:
if (place_meeting(x,y,obj_player) && keyboard_check_pressed(ord("Z")))
{
   showtext=!showtext
}

DRAW:
draw_self();

if (showtext == true)
{
   draw_set_color(c_blue);
   draw_set_halign(fa_center);
   draw_set_font(fnt_textbox_normal);
   draw_text(x,y-30," Its your# bookshelf. ")
}
works, but the textbox only goes away when the the player presses Z again and is colliding, if you walk away it still remains, any idea what to do?
 
Code:
if (place_meeting(x,y,obj_player)) {
   if (keyboard_check_pressed(ord("Z"))) {
      showtext=!showtext
   }
}
else {
   showtext = false;
}
That should fix it.
 
Top