How to do button combos?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Skydome

So I am making a fighting RPG game where there will be a few button combos. Currently I have made the four direction walking but now i want to make it so pressing up twice or down twice will make the player run in said direction.

Any tips on this? Or tutorials?

:bust_in_silhouette: Reply From: Jowan-Spooner

Hey Skydome,

one way would be to check if the player is already walking in a given direction:

var walks = null

func _process(delta):
     if Input.is_action_just_pressed("walk_up"):
         if walks == "up":
              speed = 200
              speed = 100
              walks = "up"
     elif Input.is_action_just_pressed("walk_down"):
         if walks == "down":
              speed = 200
              speed = 100
              walks = "down"
    # ...

NOTE: This way the player could wait infinitely before pressing the second time. You could use a timer to reset the walks variable like in the example below.

Another way would be to have a list of actions that were done before:

var actions = []
var timer =

func _ready():
    timer.one_shot = true
    timer.connect("timeout", self, "delete_action_history")

func _process(delta):
    if Input.is_action_just_pressed("walk_up"):
        if actions.back() == "walked_up":
            #run up
            #walk up
        do_action("walked_up", 1)

func do_action(action, time)

func delete_action_history():
    actions  = []

This system would be more advanced and could be easily adapted to more complex combinations as it would also allow to create something like this:

if Input.is_action_just_pressed("jump"):
    if ("jumped" in actions) and ("ate_berry" in actions):
        # jump again

This will allow your player to make another jump if he ate a berry during his jump.

It’s not completely perfect but it might give you a hint how you could do such a thing. Hope it helps.

Hi thanks for your reply.
Timer is how I was thinking of doing it. My game is a fighting game so there will also be other combos for fighting. A bit like little fighter or dragon ball z Buu’s fury for GBA.
Do I need to use a timer node for this to work?
Again thank you for your reply.

Skydome | 2019-05-23 14:41

You don’t need a timer but if you want it to be time based (your “action_history” clears after some seconds), yes you need (a) timer(s). It depends on what your game should be like :slight_smile:

Jowan-Spooner | 2019-05-23 15:44