How do I make to advance a animation by frame each time a press a certain button?

I would like to when i hit an object hitbox and press C, an animation appears. When I press C again, it jumps to next frame, the I press C again, then it jumps to next frame.

Just like Resident evil description for checking items and places.

I made by my own one that works, but i have to press diferentes buttons to advance until the animation ends and disappear. That’s dull…

Here’s my code:

condition: c key released
action: change animation += 1

Then if you want to create/delete the object with the same key, you need to use conditions to check the number of objects (create if 0), and the current frame (delete object if last frame).

There’s also the Dialog tree functions to take care of dialogues :slight_smile:

1 Like

Hi, apart from Gruk’s answer to use “Add to” instead of “Set to” of the animation frame,
you still can’t use same key yet.
In old Resident Evil as you mentioned, first let’s think that the “checking items and places” is done though an “Action button” - you know it will examine objects, talk to people, use items, all using the same button.
It will also do only one thing when you press the button once, and will only do another thing once you let go of the button, and press it again (nothing else will happen if you do not release the button).

In GDevelop, we do this by using “Trigger Once” condition with your key press event.

However… Due to how GDevelop events work, that alone isn’t enough (from this wiki page):

So if you made an event with “Z key is pressed” with “Trigger Once” and put every thing that button should do (opening dialogue, closing dialogue, taking item …) as a sub-event, unless you put additional conditions to avoid conflicts, every sub-event will trigger (for example, a dialogue will open and close at the same time!).

One method of “additional conditions” you can try is checking if the key is not “being pressed”, then setting a variable that makes the sub-events not trigger.

I’ll just show my example in my RPG, of beginning a dialogue interaction:

To explain this, first it checks if a certain key is pressed (in this picture it’s C key - custom control), then it checks for a Controls.KTimer.Action1 variable, and the following events set the same variable to 1. In another event it will check if this variable is 0, so that events that conflict does not happen (I don’t want to close dialogue box after opening it).

Then, at bottom of all events, I check if this key is released:

First it checks if the variable is above 0, and then it checks if the key is NOT being pressed.

Whew, that was longer than it should be, but I’m not sure how to simplify the KTimer part. Hope it helps!
Also, I +1 Gruk’s suggestion to use Dialogue Tree - if your game has any kind of dialogue syste, it’s easier to use it in the end, although starting is really confusing. Feel free to check out the example project, or create a new topic if you’re stuck somewhere there!

1 Like

Thanks buddy, your answer is pretty rich on details. I’'ll read it carefully and try out. Any doubt i get back here.

I’ll try that on the first hand, se if it works. Thanks pal :slightly_smiling_face:

1 Like

The thing I still dont get is how to use variables at all.
If a create an “Action button = C”, for example, do I have to create Global Variables to match all uses of this button on the game or scene?
Example: Action button is C, variable 1= examine items
variable 2=talk
variable 3=attack
variable 4=next text line
and so on?

I see we can give the variables a name, but we need to put an value as well, which sometimes is number and sometimes is text. That confuses me…

Nice question - not really, you don’t have to use variables for everything. In your “variable 4=next text line” example, it’s a condition, of the Dialogue Tree extension.
Read about it here and see this example:

If that doesn’t make sense, that’s fine. You will need to learn how the Online Example provided in that page I linked, uses dialogue, and sadly I don’t have the time to explain it myself.
Try to look through the events of the code, and change some little bits of it, then run the example project again to see what your changes do to it - that’s a good way to learn.
If, while learning about Dialogue Tree you have a specific question, though, then asking a specific question, will be easier to answer it.

Same goes for variables - essentially, they let you tell the game to do different things based on their value, and it’s up to you if you want to make them numbers (only needed if you do math operation) or text. Also, when events are considered, talking to a person or examining an object will generally use same kind of events/code.
Beyond that, I can only link you this wiki page, or by looking up Progamming Variables on Youtube, I’m sure someone can explain it really well there.