GML [Solved] Textboxes and writing and not writing keyboard_string

X

XirmiX

Guest
I guess that for solved topics, expecting to get any more advice isn't going to happen:

Well, I guess I'll have to reiterate in a new topic. Essentially, apparently within that topic "keyboard_string = "";" works as a way of preventing a string writing into a text box or whatever else without writing in values that weren't typed in while the box was selected, but while deselected aaand allows for you to safely select and deselect the box without any issue. Well, doesn't work for me...

Essentially I want to make sure that you can write text in the text box while it is selected and not while it's unselected, but I also want to make sure that the text doesn't get erased upon you deselecting it. With the following code:

Code:
if self.selected == true
{
    keyboard_check(vk_anykey)
    {
        if (string_length(keyboard_string) < max_char)
        {
            txt = keyboard_string;
        }
        else
        {
            keyboard_string = txt;
        }
    }
}
I get the keyboard_string written in, whether I had or had not selected the text box, after I select the text box, and that is because keyboard_string is always read by the computer... always... but then with this code:

Code:
if self.selected == true
{
    keyboard_check(vk_anykey)
    {
        if (string_length(keyboard_string) < max_char)
        {
            keyboard_string = "";
            txt = keyboard_string;
        }
        else
        {
            keyboard_string = txt;
        }
    }
}
I don't get anything written. Do I need keyboard_string=""; in a different spot? Possibly. Though I still don't see this solving my issue. Take in note that I plan to have multiple of these text box instances on-screen for different things, so I need this to be as applicable to individual instances as possible.

So, how would I get to have:
1) string in textbox only writing when the texbox is selected.
2) nothing typed while the textbox is deselected to be written or deleted from the textbox.
3) have everything within the text box stay as is when you re-select it after having something typed in it the previous time and being able to continue to type from after the last string's position.

Oh, and self.selected is initially set to false in create event, txt is set there as an empty string and max_char is set to 30, so that the user can't type beyond 30 characters.
 

Jakylgamer

Member
Draw event:

Code:
if selected == true {
    var tt = keyboard_string;//set keyboard string to a temp var
    if (string_length(tt) > 30) { //make sure it doesnt go over the desired length
        //if it does go over we set it back to the length correct length
        keyboard_string = string_copy(tt, 1, 30);
        text = tt
    }
    //these are just to update text variable (this is the variable to hold the key string value)
    var update_keys = keyboard_check_pressed(vk_backspace) || keyboard_check_pressed(vk_enter) ;
    if  (update_keys) {
        text = tt;
    }
    //draw the text
    draw_text(x,y,tt);
} else {
    //this is the text when not selected
    draw_text(x,y,text);
}
Left click pressed event:
Code:
//reset keyboard string to selected boxes text
keyboard_string = text;
//make sure we deselect other boxes
with(obj_tbox) selected = false;
//then we select the one we clicked on
selected = true;
im sure theres better ways to do this but this is off the top of my head .
hope it helps :)
 
Last edited:
Top