0 votes

I am creating a game and am having trouble understanding what the best approach is in Godot for coding in player actions. The scenario is a player clicking on a tile in a 3D isometric game which will trigger them to move to the tile then play out an action on it (cut down tree, mine a rock, etc), and then once done receive xp/items for doing it.

So as a series of steps:

  1. Player input
  2. (optional) path find and move character
  3. do player action (an animation)
  4. show progress bar
  5. check xp gain
  6. check item gain
  7. show xp pop-up
  8. show item pop-up
  9. (optional) if levelled up then show level up dialog
  10. (optional) if finished activity show quest dialog

If done all as event signals that is a lot, and a lot of data to pass through everything to make sure they all know what to do. Normally if coding in another language this would be coded with callbacks, or a top level state machine.

So how have other people approached this, do I just go with events, or add in some callbacks or is there a different way I haven't thought of?

in Engine by (134 points)

1 Answer

0 votes
Best answer

I have since discovered yield():

https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html?#coroutines-with-yield

This approach I believe is the best for asynchronous tasks like waiting for animations and timers, while keeping your code readable and tidy

by (134 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.