I am not getting errors with this code, but I’m also not seeing any positions populate in the Inspector under the Roster heading.
It might be because I was trying to modify what you put up. Here’s what I currently have:
@tool
@icon("icon.svg")
class_name Player
extends Resource
enum Position {
ATHLETE,
QUARTERBACK,
CENTER,
GUARD,
TACKLE,
HALFBACK,
FULLBACK,
WIDE_RECEIVER,
TIGHT_END,
DEFENSIVE_END,
DEFENSIVE_TACKLE,
OUTSIDE_LINEBACKER,
INSIDE_LINEBACKER,
STRONG_SAFETY,
CORNERBACK,
FREE_SAFETY,
LONG_SNAPPER,
KICKER,
PUNTER
}
enum Depth {
STARTER,
BACKUP,
THIRD_STRING,
FOURTH_STRING,
FIFTH_STRING,
SIXTH_STRING,
EIGHTH_STRING,
NINTH_STRING,
TENTH_STRING
}
@export var position: Position = Position.ATHLETE
@export var position_depth: Depth = Depth.STARTER
@export_range(1.0, 100.0, 1.0) var speed: float
@export_range(1.0, 100.0, 1.0) var strength: float
@export_range(1.0, 100.0, 1.0) var agility: float
@export_range(1.0, 100.0, 1.0) var throw_accuracy: float
@export_range(1.0, 100.0, 1.0) var throw_read: float
@export_range(1.0, 100.0, 1.0) var catching: float
@export_range(1.0, 100.0, 1.0) var routes: float
@export_range(1.0, 100.0, 1.0) var run_read: float
@export_range(1.0, 100.0, 1.0) var run_block: float
@export_range(1.0, 100.0, 1.0) var pass_block: float
@export_range(1.0, 100.0, 1.0) var pass_rush: float
@export_range(1.0, 100.0, 1.0) var run_gap: float
@export_range(1.0, 100.0, 1.0) var run_fit: float
@export_range(1.0, 100.0, 1.0) var blitz: float
@export_range(1.0, 100.0, 1.0) var man_cover: float
@export_range(1.0, 100.0, 1.0) var zone_cover: float
@export_range(1.0, 100.0, 1.0) var kick_accuracy: float
@export_range(1.0, 100.0, 1.0) var punt_accuracy: float
@export_range(1.0, 100.0, 1.0) var snap_accuracy: float
func _init() -> void:
speed = randf_range(50.0, 100.0)
strength = randf_range(50.0, 100.0)
agility = randf_range(50.0, 100.0)
throw_accuracy = randf_range(50.0, 100.0)
throw_read = randf_range(50.0, 100.0)
catching = randf_range(50.0,100.0)
routes = randf_range(50.0,100.0)
run_read = randf_range(50.0,100.0)
run_block = randf_range(50.0,100.0)
pass_block = randf_range(50.0,100.0)
pass_rush = randf_range(50.0,100.0)
run_gap = randf_range(50.0,100.0)
run_fit = randf_range(50.0,100.0)
blitz = randf_range(50.0,100.0)
man_cover = randf_range(50.0,100.0)
zone_cover = randf_range(50.0,100.0)
kick_accuracy = randf_range(50.0,100.0)
punt_accuracy = randf_range(50.0,100.0)
snap_accuracy = randf_range(50.0,100.0)
if speed >= 83.0 and strength >= 81.0 and agility >= 82.0 and throw_read <= 79.0 and run_read <= 81.0 and zone_cover <= 80.0 :
position = Position.ATHLETE
if throw_accuracy >= 80.0 and throw_read >= 80.0:
position = Position.QUARTERBACK
elif speed >= 85.0 and strength >= 75.0 and run_read >= 82.0 :
position = Position.HALFBACK
elif speed >= 78.0 and speed <=83.0 and strength >= 80.0 and run_read >= 78.0 :
position = Position.FULLBACK
elif agility >= 50.0:
position = Position.TIGHT_END
```
I wanted to keep the values between 50 and 100 and add extra parameters to keep player positions within tighter ranges.
That way, I won’t have players with 2 Speed. Football requires tight ranges, especially at the pro level, where speed is within hundredths of a second, often.
I also need to add height and weight attributes, which I have started on, as you might notice.
Do you think my parameters are too stringent for the program to find any players adequate for the position?
I did put that Node code into a Node script, by the way. That is in the game, and I named it Roster like you did, and it does show up in the Inspector. It just doesn’t have any players populating underneath it.
Edit: just realized my height and weight parameters are gone. Must have happened when I was trying to fix the error messages. So they aren’t there.
Further explanation: the depth enum was changed too, because I wanted the player to be able to put as many players of any type at the starting position on the roster. So, if you want to roster 11 QBs on offense and line them up at the O line positions and all the skill positions, go ahead! The results won’t be great, but… you can do it.