Turn System and Signals

Godot Version

4.3

Question

Hello there (: so I’m learning GDScript and making something like a rpg dungeon crawler and I have to make the ‘Turn System’ for combat.

So first I thinked of having a turn handler and while combat is on depending on who should play (player or npc) call their respective player_turn or npc_turn functions but this will lead in calling multiple times the player_turn since waiting for the player input on what actions take would take longer than running the npc script.

So I want to avoid this behavior since it doesn’t feel right, maybe it is (if that’s the case it would be awesome to know)

Then I had the idea of using some custom signals, and should be something like this:

  • Combat starts
  • First turn is decided (let’s assume player go first)
  • Player takes his time to decide what to do
  • When player is out of actions to do in his turn or skips the turn emit a signal to npc turn
  • Npc turn is scripted so it will be linear in execution
  • emit a signal to player turn

So far this looks great but I’m not sure about the next thing, when I emit a signal the function where this signal comes from keeps hanging until the reception function ends their execution?

I know I made a long post to make a simple cuestion but anybody have a different approach to solve this system is also appreciated, thanks and a have a nice day :smile:

I’m not entirely sure what you’re asking, but you’re idea sounds good! One thing you didn’t mention is that you don’t have to have signals call a function, instead you can use the await keyword to control the flow of your game!

For example, you could have this in the ready function of your battle scene:

while not is_battle_over: 
    player.begin_turn()
    await player.turn_ended
    enemy.begin_turn()
    await enemy.turn_ended

I’ve done something similar for a game jam, but it could probably be improved to make it more extensible. Hope this helped!

1 Like

I didn’t thinked about await probably that’s what I was searching for, thank you! :slight_smile: