我是Godot的使用者,我一直在关注Godot教程,买Godot说
无效的设置索引'武器'(在基础上:'空间')具有类型的价值 '空间(auber_manager.gd)'。
我的代码如下:
extends Spatial
# All weapons in the game
var all_weapons = {}
# Carrying Weapons
var weapons = {}
#HUD
var hud
var current_weapon #Reference to the current weapon extension???
var current_weapon_slot = "Empty" # The current weapon slot
var changing_weapon = false
var unequipped_weapon = false
func _ready():
hud = owner.get_node("HUD")
all_weapons = {
"Unarmed" : preload("res://Unarmed.tscn"),
"Pistol_A" : preload("res://pistol_a/pistol.gd"),
"Rifle_A" : preload("res://rifle_a/rifle_a.tscn")
}
weapons = {
"Empty" : $Unarmed,
"Primary" : $Pistol_A,
"Secondary" : $Rifle_A
}
# Initializing refernces for each weapon
for w in weapons:
if weapons[w] != null:
weapons[w].weapon_manager = self
weapons[w].player = owner
weapons[w].visible = false
# Set current weapon to unarmed
current_weapon = weapons["Empty"]
change_weapon("Empty")
# Disable process
set_physics_process(false)
func _process(delta):
if unequipped_weapon == false:
if current_weapon.is_unequip_finished() == false:
return
unequipped_weapon = true
current_weapon = weapons[current_weapon_slot]
current_weapon.equip()
if current_weapon.is_equip_finished() == false:
return
changing_weapon = false
set_process(false)
func change_weapon(new_weapon_slot):
if new_weapon_slot == current_weapon_slot:
current_weapon_slot.update_ammo()
return
if weapons[new_weapon_slot] == null:
return
current_weapon_slot = new_weapon_slot
changing_weapon = true
weapons[current_weapon_slot].update_ammo()
# CHanging weapons
if current_weapon != null:
unequipped_weapon = false
current_weapon.unequip()
set_process(true)
# Update HUD
func update_hud(weapon_data):
var weapon_slot = "1"
match current_weapon_slot:
"Empty":
weapon_slot = "1"
"Primary":
weapon_slot = "2"
"Secondary":
weapon_slot = "3"
hud.update_weapon_ui(weapon_data, weapon_slot)
Invalid set index 'weapon' (on base: 'Spatial') with value of type
'Spatial (weapon_manager.gd)'.
My code is below:
extends Spatial
# All weapons in the game
var all_weapons = {}
# Carrying Weapons
var weapons = {}
#HUD
var hud
var current_weapon #Reference to the current weapon extension???
var current_weapon_slot = "Empty" # The current weapon slot
var changing_weapon = false
var unequipped_weapon = false
func _ready():
hud = owner.get_node("HUD")
all_weapons = {
"Unarmed" : preload("res://Unarmed.tscn"),
"Pistol_A" : preload("res://pistol_a/pistol.gd"),
"Rifle_A" : preload("res://rifle_a/rifle_a.tscn")
}
weapons = {
"Empty" : $Unarmed,
"Primary" : $Pistol_A,
"Secondary" : $Rifle_A
}
# Initializing refernces for each weapon
for w in weapons:
if weapons[w] != null:
weapons[w].weapon_manager = self
weapons[w].player = owner
weapons[w].visible = false
# Set current weapon to unarmed
current_weapon = weapons["Empty"]
change_weapon("Empty")
# Disable process
set_physics_process(false)
func _process(delta):
if unequipped_weapon == false:
if current_weapon.is_unequip_finished() == false:
return
unequipped_weapon = true
current_weapon = weapons[current_weapon_slot]
current_weapon.equip()
if current_weapon.is_equip_finished() == false:
return
changing_weapon = false
set_process(false)
func change_weapon(new_weapon_slot):
if new_weapon_slot == current_weapon_slot:
current_weapon_slot.update_ammo()
return
if weapons[new_weapon_slot] == null:
return
current_weapon_slot = new_weapon_slot
changing_weapon = true
weapons[current_weapon_slot].update_ammo()
# CHanging weapons
if current_weapon != null:
unequipped_weapon = false
current_weapon.unequip()
set_process(true)
# Update HUD
func update_hud(weapon_data):
var weapon_slot = "1"
match current_weapon_slot:
"Empty":
weapon_slot = "1"
"Primary":
weapon_slot = "2"
"Secondary":
weapon_slot = "3"
hud.update_weapon_ui(weapon_data, weapon_slot)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
auber_manager.gd
文件似乎缺少一个称为武器
的变量,因此将其设置为不可能。另外,我找不到该错误在此脚本文件中的位置;它可能起源于您的代码中的其他地方。
确保您使用正确的变量名称,并尝试在正确的对象上设置值。
Your
weapon_manager.gd
file seems to lack a variable calledweapon
, and thus setting it is impossible.Also, I can't find where the error would originate in this script file; it probably originated somewhere else in your code.
Make sure you're using the right variable names, and trying to set values on the right objects.