How Do I Get Draw_Text to Persist After Click Event?

GarbageHaus

Member
I am trying to create something where a button is pressed and text appears in a box but I am stuck on the most basic steps. For example I have the following Draw Event tied to my button:
GML:
//Press Vs to Get Monsters
var monster1 = ["Fire",55,"Dragon"]
draw_sprite(spr_vs,0,x,y)
if mouse_check_button(mb_left) then draw_text(x,y,monster1[2])
This creates the text but it is not in the box I need it in and once I release the mouse button, the condition is no longer true and therefore the text goes away.

I've tried other methods such as making the line be:
GML:
if mouse_check_button(mb_left) then obj_textbox.draw_text(x,y,monster1[2])
in the hopes that by using the draw_text function tied to another Object it will not clear it automatically once the condition stops being true, thus solving both problems. However, this yielded an exception so I'm sure my syntax is wrong somewhere.

I've tried using other Events besides "Draw" but for some reason "Draw_text" only seems to function as part of an if statement or within the "Draw" Event except in the "Mouse - Left Down" event where it does not function at all.

How am I supposed to click a button and have a "textbox" Object contain said text after clicking?
 

Coded Games

Member
Create event:
Code:
clicked = false;
Step:
Code:
if (mouse_check_button(mb_left)) {
     clicked = true;
}
Draw:
Code:
var monster1 = ["Fire",55,"Dragon"]
draw_sprite(spr_vs,0,x,y)
if (clicked) {
    draw_text(x,y,monster1[2])
}
Draw events are constantly called and mouse_check_button only will be true while you are holding down the button. So you need another variable to store if the moue has ever been clicked. Check if the mouse is click in step then set your variable to true. Then in draw check if that variable is true. If you ever want the text to disappear then set clicked to false.

All draw_ functions only work in draw events. Also I have no clue if the "then" keyword actually does anything. I've never used it. Your second bit of code is not valid GML as draw_text is a global function, not a instance function. Even then it would be called from whatever event it was in.
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
How am I supposed to click a button and have a "textbox" Object contain said text after clicking?
  1. Give the textbox a variable my_string
  2. In its draw event, draw_text(x,y,my_string)
  3. Set its my_string to the text you want when creating the textbox object instance.
 
Top