Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rensae |
Hey there ! I’m trying to get a turn based combat to work, I know that I’m close to it, but I’m lacking some knowledge to finish it. Here is the code I’m using (following a tutorial I found on it):
onready var active_character
func intialize():
var mobs = get_mobs()
mobs.sort_custom(self, "sort_mobs")
for mob in mobs:
mob.raise()
active_character = get_child(0)
static func sort_mobs(a, b):
#take speed of a and b, compare them and return the fastest
return a.speed > b.speed
func play_turn():
#wait for the character turn to end
yield(active_character.play_turn(), "completed")
#modulo the child count to go to 0 after finishing the child count
var new_index : int = (active_character.get_index() + 1) % get_child_count()
make active_character the next child to play
active_character = get_child(new_index)
func get_mobs():
#get the childrens
active_character = get_children
I have 6 characters and 6 ennemies, each have their own stats in their own scripts, and all of them are childrens of the TurnQueue nodes I made and who has this script
I’ll gladly take any help, and sorry if this is obvious for some of you