Hello, I am trying to create a simple turn-based movement demo. Currently, there are three separate sprites that move across the screen a predefined distance upon the right arrow key press. I want them to each take turns moving. One press of the right arrow key should be one movement, and then it should allow the next Sprite to move, then the next sprite after that.
Originally, I used signals to move the first, then second, third, and lastly fourth sprite. But I could not find a way to loop back around in the queue and start again. They would all begin moving again together afterwards. I've tried following GDQuest's turn-based movement demo, but having trouble putting it all together.
The structure looks like this:
- Sprite 1
- Sprite 2
- Sprite 3
- Sprite 4
All of my sprites all use the following code:
var velocity = Vector2(0, 0)
var speed = 200
velocity.x = 50
global_position += velocity * speed * delta
I'm trying to manage the turns by using the following script on the parent Node2D.
onready var active_character
active_character = get_child(0)
var new_index : int = (active_character.get_index() + 1) % get_child_count()
active_character = get_child(new_index)
I connected the
"end_turn" signal from each child to the parent
play_turn() function already. What happens now is that the first sprite moves once, then I get the following error: "First argument of yield() not of type object."
Is there a way to fix this? Or am I approaching it all wrong? Your help is much appreciated. I am still very new to Godot but I am happy to answer any other questions about the code.