From 1892ab778d84bad77f533ce5a7baf6fd25d0c357 Mon Sep 17 00:00:00 2001 From: asheraryam Date: Sat, 20 Jul 2019 21:00:11 +0300 Subject: [PATCH] Fix game crashing when player dies. Instead, the game will restart from the beginning. --- actors/player/PlayerController.gd | 2 ++ actors/player/PlayerStateMachine.gd | 3 ++- utils/state/StateMachine.gd | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/actors/player/PlayerController.gd b/actors/player/PlayerController.gd index bb07908..d84b298 100644 --- a/actors/player/PlayerController.gd +++ b/actors/player/PlayerController.gd @@ -45,6 +45,8 @@ func fall(gap_size): func _on_Die_finished(string): set_dead(true) + get_tree().change_scene("res://Demo.tscn") + func get_health_node(): return $Health diff --git a/actors/player/PlayerStateMachine.gd b/actors/player/PlayerStateMachine.gd index f2962bc..6f48bbe 100644 --- a/actors/player/PlayerStateMachine.gd +++ b/actors/player/PlayerStateMachine.gd @@ -37,7 +37,8 @@ func _unhandled_input(event): _change_state('attack') get_tree().set_input_as_handled() return - current_state.handle_input(event) + if current_state: + current_state.handle_input(event) func _on_Health_damage_taken(new_health): _change_state('stagger') diff --git a/utils/state/StateMachine.gd b/utils/state/StateMachine.gd index 1c69859..e9c51a4 100644 --- a/utils/state/StateMachine.gd +++ b/utils/state/StateMachine.gd @@ -33,7 +33,8 @@ func set_active(value): current_state = null func _unhandled_input(event): - current_state.handle_input(event) + if current_state: + current_state.handle_input(event) func _physics_process(delta): current_state.update(delta)