#Exported array variables getting default values on _ready()

9 messages · Page 1 of 1 (latest)

safe dust
#

I'm following the tutorial "Making an FPS Weapon Manager in Godot 4" (around 13:00 in https://youtu.be/dTW9jIIdbPU?t=765) and i'm having problems with empty "start_weapons" and "_weapon_resources". I did filled these variables in the editor as the first image shows and the second one shows the error. The code bellow is from weapons_manager.gd (linked with weapons_manager node)

# current held weapons
var weapon_stack = []

# weapon_stack index
var weapon_index = 0

var next_weapon: String

# all game weapons
var weapon_list = {}

@export var _weapon_resources: Array[Weapon_Resources]
@export var start_weapons: Array[String]


func _ready():
    Initialize(start_weapons)

# enter the state machine
func Initialize(_start_weapons: Array):
    for weapon in _weapon_resources:
        weapon_list[weapon.weapon_name] = weapon
    
    # add starting weapons
    for i in _start_weapons:
        weapon_stack.push_back(i)
    
    current_weapon = weapon_list[weapon_stack[0]]
tepid niche
#

Could it be that you accidentally attached that script to another node?

cold fossil
#

I'm totally clueless, but maybe restarting Godot could fix it?

safe dust
safe dust
tepid niche
#

If you make a new empty test scene, add one node and attach this script there set the weapons and run it, does that work?

safe dust
tepid niche
#

func Initialize(_start_weapons: Array[String])