gdquest-demos / godot-3-demos

Dozens of free and open source demos for the Godot game engine, version 3. Head to the link below for newer demos for Godot 4+
https://github.com/gdquest-demos/
MIT License
1.85k stars 978 forks source link

godot-demos/2018/04-24-finite-state-machine/ 'previous' not working #67

Open MikyGus opened 4 years ago

MikyGus commented 4 years ago

I'm submitting a...

Bug report

What is the current behavior? The 'previous' functionality is not working

What is the expected behavior? To go to the previous state

Tell us the steps to reproduce the bug, and if possible share a minimal demo of the problem.

Found the problem in '/player_v2/state_machine.gd' func _change_state(state_name): if not _active: return current_state.exit()

if state_name == "previous":
    states_stack.pop_front()
else:
    states_stack[0] = states_map[state_name] <-- **Remove this**
        states_stack.push_front(states_map[state_name]) <-- **Replace with this**

current_state = states_stack[0]
emit_signal("state_changed", current_state)

if state_name != "previous":  <-- **Remove this**
    current_state.enter() <-- **We whant to enter the previous state**