Changing text by pressing/releasing key

Hello everybody,

I’m a beginner in game creating and in GDevelop. I’m currently working on a small game of my own to learn game development. So far, the tutorials and the forum have helped me a lot (thank you to everyone), but now I encountered a problem that I couldn’t find a solution for.

I have a text object with, of course, some text in it. Since not all of the text fits onto the screen, I want the player to press a key to continue the text passage; I’ve seen this in other games and found it would be great for my little project. I made a key event (in my case pressing the space bar) that should change the old text into the new text, but unfortunately, after releasing the key, the new text jumps back to the old text.

The event looks like this:
Condition: At the beginning of the scene
Action: Do “Text1” to TextObject
Condition: Space key is pressed
Action: Do “Text2” to TextObject

I tried out several things on my own (like releasing the space key), I also looked into the tutorials and in the forum and tried out what I found there, but nothing has worked so far. What can I do so that the new text stays there after pressing and releasing the key?

I hope somebody can help, thank you in advance :slight_smile: .

Something like this seems to work well:

But there are many different ways to do it I’m sure.
Note that space key “released” is used, because this will only change the text once for each space key press + release. I guess the theory is that if the space key is released, it had to be pressed first.

If we just had space key pressed, it would change rapidly to 1,2 while holding the space button.

It should work. Are you sure you don’t change the text anywhere else? If you change the text on key press, it should remain changed even after you release the key unless you change the text again somewhere else.

I missed “at the beginning of the scene” and thought it was an empty event action that was putting it back, but you’re right.

I’m not sure what you mean with “change the text anywhere else”? The text object originally is hidden at the beginning of the scene, and the text then appears/changes after a few seconds because I set the timer like this, I forgot to mention that. Maybe it has something to with that?

Thank you for your answer :slight_smile: .

Thanks for your reply, I will try it out :slight_smile: .

The events you described should not change the text after release the space key, there must be an other event that cause the text to change when the space key is released.

If you don’t reset and pause the timer, yes it is possible because the condition “If timer is greater than X second” always going to be true and always execute the actions. You always need to stop and pause the timers once you don’t need them any more. You can also try to use the “Trigger Once” condition to make sure it triggered only one time but in general, always best to pause and reset the timers after use if you don’t need them.

Thank you both for your help, it works now with kalel’s suggestion, but I keep your tip in mind, ddabrahim, working with timers is still difficult for me :slight_smile: .