Textbox Focus/Unfocus issues [SOLVED]

0 favourites
  • 3 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Hi, I'm having some issues focusing and unfocusing a textbox. I was working on a large project when I bumped into this issue, so I made a smaller one to isolate the problem.

    This small project starts with a blank layout, if you press Enter or C a textbox becomes visible, focused and an instance variable is set to True. If then you press Enter the textbox becomes invisible, unfocused and the variable is set to false. Basically, pressing Enter or C should switch the textbox on and off.

    It mostly works, except for a small issue that is bothering me. After making the textbox invisible I have to press C twice in order to make it visible again (it should work with a single press), with Enter it works with a single press (as it should). It is as if even after unfocusing and making the textbox invisible the C key is still not registered by the event sheet (it could be something else, but that is the impression I'm getting).

    Event sheet:

    Capx:

    https://www.dropbox.com/s/p8lm5tmzkus9knx/TestFocus.capx?dl=0

    Some other things worth mentioning...

    * If I'm understanding things correctly, when you press most keys when a textbox is focused the key "goes" into the textbox and not the event sheet, so, if there are events related to key presses they get ignored. Because of this, even if according to my event sheet, when pressing C while the textbox is visible it should become invisible, It doesn't (that's ok, it actually fits the behavior I'm trying to achieve).

    * If I use C to turn the textbox visible for the first time it works ok (with a single press). But if I've pressed the C key before, I'll need to press it twice.

    * At some point I made another variation, instead of making the textbox visible/invisible I created it and destroyed it each time, the results were the same.

    * At some point I added a text object and the action of appending an X to it as soon as the C key was pressed (no more conditions or subevents). This was to observe if the event of pressing C was being triggered or not. I noticed that when I had to press C twice, the first press was not triggering the append action at all.

    What I'm expecting to happen:

    1) Press C: Textbox becomes visible

    2) Press Enter: Textbox becomes invisible

    3) Press C: Textbox becomes visible again

    What actually happens:

    1) Press C: Textbox becomes visible

    2) Press Enter: Textbox becomes invisible

    3) Press C: Nothing happens

    4) Press C: Textbox becomes visible again

    Also, another minor issue. Just by using the Focus action the textbox doesn't get focus, I had to add a Wait action to make it work. Any ideas why?

    Well, I guess that is all the information I can provide. I hope somebody can tell me what am I doing wrong.

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, i got it. (you want to do a chat, with the quick key access "C" ya?? )

    First, i prefer to work with number variables.

    Create a number variable in the text box. (i named "switch") with the initial value = 1 (we will use 0 to unfocused and invisible, and 1 to visible and focused, okay?)

    And do This:

    I don't know why, but the event that fixed this issue was the "On C released"

    Tell me what happened for you.

  • Awesome

    Thank you very much HItskin.

    Yep, changing visibility and focus actions into the variable's values events instead of the keypress events, and using the key released event did the tricks.

    I just changed the events a little so Enter would also show the textbox if it is invisible.

    Oh, but it is not a chat, just the option to change the name of your save file (for 2d games I like to use the arrow keys for movement and Z, X, C and V for other actions. In this case C is the "OK" button).

    Anyway, thanks for your help

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)