Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix game crashing when player dies. Instead, game restarts. #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

realkotob
Copy link

Fixes #93

Let me know if you'd like this handled in a different way.

I did the simplest way possible, but I could also add a "Game Over" screen if you could specify exactly how it should look like.

Copy link
Contributor

@NathanLovato NathanLovato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help, the code needs changes though. You can find our contributors' guide here if you need a hand with the git workflow: https://www.gdquest.com/open-source/guidelines/contributing-to-gdquest-projects/ (NB: still a work in progress)

@@ -45,6 +45,8 @@ func fall(gap_size):

func _on_Die_finished(string):
set_dead(true)
get_tree().change_scene("res://Demo.tscn")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be in the player script. Rather in a file like Game.gd or something similar.

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be part of the same commit as it's unrelated. Also, I have to check the code but I feel it's not the right fix to keep the code maintainable. There shouldn't be cases where the input gets forwarded to a nonexistent state.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the player performed queue_free so the old reference does not exist anymore.

Additionally _unhandled_input is an internal engine method so it can't be avoided without other changes. I would suggest not doing queue_free on the player and instead just setting to a Dead state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to get back into the code, the state machine should belong to the player and be freed with it. And yeah it probably shouldn't call queue_free upon dying then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid call. Nonexistent function 'handle_input' in base 'Nil'.
2 participants