Best practice for a coding a long chain of actions

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

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?

:bust_in_silhouette: Reply From: beaverusiv

I have since discovered yield():

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