Godot Version###
4.2
Question###
for some reason, when I try and use my code. it tells me that invalid get index(“ammo”) but the resource it is getting from has the correct name.
if anyone needs me too.
extends Node3D
class_name weapons_manager
signal Update_WeaponStack
var current_weapon = null
var WeaponStack =
var weapons_list = {}
var Next_Weapon: String
var weaponIndicator = 0
@export var _weapon_resources: Array[Weapon_resource]
@export var Start_Weapons: Array[String]
@onready var weapon_cast := get_node(“%RayCast3D”)
@onready var Anim_player := get_node(“%AnimationPlayer”)
#gets weapons.
func initialize(_Start_Weapons: Array):
for Weapons in _weapon_resources:
Weapons.ready()
weapons_list[Weapons.weapon_name] = Weapons
for child in Start_Weapons:
WeaponStack.push_back(child)
current_weapon = weapons_list[WeaponStack[0]]
Update_WeaponStack.emit(WeaponStack)
enter()
func enter():
Anim_player.queue(current_weapon.equip_anim)
func exit(_next_Weapon: String):
if _next_Weapon != current_weapon.weapon_name:
if Anim_player.get_current_animation():
Anim_player.queue(current_weapon.equip_anim)
Next_Weapon = _next_Weapon
func Change_Weapon(weapon_name: String):
current_weapon = weapons_list[weapon_name]
Next_Weapon = “”
enter()
func _input(event):
if event.is_action_pressed(“weapon_up”):
pass
if event.is_action_pressed("weapon_down"):
pass
if event.is_action_pressed("shoot1"):
shoot()
func shoot():
if current_weapon.ammo != 0:
if !Anim_player.is_playing():
Anim_player.play(current_weapon.shoot_anim)
current_weapon.ammo -= 1
if weapon_cast.is_colliding():
var collider = weapon_cast.get_collider()
hit_damage(collider)
func hit_damage(collision):
if collision.is_in_group("test"):
print ("test")
if collision.is_in_group("door_handle"):
print("door_handle")
if collision.is_in_group("enemy"):
print("enemy")
if collision.is_in_group("test_enemy"):
print("test_enemy")