Help accessing information inside of a resource

Godot Version

4.2.1

Question

I am trying to make a node to keep track of an turn system it reads from a group “is_in_turnorder” so i know who to include in the turn order and it checks every node and grabs their Initiative (Initiative is defined in a resource/class called AttackStat. this class/resource that is attached to each enemy/player and orders them based off of whoever has the highest Initiative stat, and then goes through the list

my issue is that from the turn system node i cant Access the resource AttackStat that is tied to the enemy node

class_name TurnQueue
var entities =
var your_turn: bool

func _ready():
entities = get_tree().get_nodes_in_group(“is_in_turnorder”)
# this correctly grabs all the entities and prints their names if asked
entities.sort_custom(_compare_speed)
# this doesn’t work i tried entities.AttackStat.sort_custom(_compare_speed)

    start_turn()

func _compare_speed(a, b):
# Custom function to compare speeds
return a.speed > b.speed

I then get this error Invalid get index ‘AttackStat’ (on base: ‘Array[Node]’).

Sorry im new to godot and game dev if anyone needs more info please let me know

What is the error message you get when you use the first option:
entities.sort_custom(_compare_speed)

When posting code use the </> button to enclose your code and format it properly.

2 Likes
Invalid get index 'Initiative' (on base: 'Node2D (Enemy)').

this is the information im trying to access and im trying to get it from the turnqueue

I found the issue 1 was a syntax issue i believe writing
var Initiative = attack_stat.initiative
instead of var Initiative: = attack_stat.initiative

and the other was trying to acsess the stats from the array entities instead of playing through the array and reading stats from there