godot 4.3
Question
`how i can fix this code, and why my varible has int type value
Invalid assignment of property or key ‘mesh’ with value of type ‘ArrayMesh’ on a base object of type ‘Array’.
armas_1[0].mesh = load(arma[“model”]) # line where the error is
armas_2[0].mesh = load(arma_loader[“model”])`
#the rest of the code
extends Node3D
@export var armas_1 : Array
@export var armas_2 : Array
var armas_ : Array
@export var arma_escolhida1 : int
@export var arma_escolhida2 : int
@export var armas_escolhidas : Array
var arma_segurando : int
var arma_nao_segurando : int
var bala_load : PackedScene = load(“res://gun_base/bala.tscn”)
var delay : bool = false
var spawn_point : Vector3
var _00 : Dictionary = {“name” : “assaug”,
“id” : “_00”,
“municao_atual” : 40,
“max_ammo” : 40,
“model” : “res://gun_base/ryfle_1.tres”,
“ammo_total” : 320,
“shotdelay” : 0.140,
“markerx” : 0.0,
“markery” : 0.043,
“markerz” : 0.45,
“dano” : 10,
“veloz” : 2.5,
“delay” : 0.145}
var _01 : Dictionary = {“name” : “mk_200”,
“id” : “_00”,
“municao_atual” : 35,
“max_ammo” : 35,
“model” : “res://gun_base/smt_1.tres”,
“ammo_total” : 300,
“shotdelay” : 0.95,
“markerx” : 0,
“markery” : 0,
“markerz” : 0,
“dano” : 7,
“veloz” : 3.0,
“delay” : 0.115}
var lista_de_armas : Array
Called when the node enters the scene tree for the first time.
func ready():
armas = [get_node(“ARMA1”), get_node(“ARMA2”)]
armas_1.append(arma_escolhida1)
armas_2.append(arma_escolhida2)
print(armas_1)
print(armas_2)
lista_de_armas = [_00, _01]
armas_escolhidas = [arma_escolhida1, arma_escolhida2]
trocar_arma(arma_escolhida1, true, arma_escolhida2)
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _input(event):
if Input.is_action_just_pressed(“1”):
arma_segurando = 0
arma_nao_segurando = 1
trocar_arma(arma_escolhida1, false, )
elif Input.is_action_just_pressed(“2”):
arma_segurando = 1
arma_nao_segurando = 0
trocar_arma(arma_escolhida2, false, )
func _on_timer_timeout():
delay = false
func _physics_process(delta):
if Input.is_action_pressed(“mouse”) and !Input.is_action_pressed(“1”) and !Input.is_action_pressed(“2”) :
shot()
func trocar_arma(arma_pegando : int, load : bool, arma_load : int = 0):
var arma = lista_de_armas[arma_pegando]
if load == !false:
var arma_loader = lista_de_armas[arma_load]
armas_1[0].mesh = load(arma["model"])
armas_2[0].mesh = load(arma_loader["model"])
var node_arma = Marker3D.new()
armas_1[0].add_child(node_arma)
node_arma.global_position.x = arma["markerx"]
node_arma.global_position.y = arma["markery"]
node_arma.global_position.z = arma["markerz"]
else:
armas_[arma_segurando].visible = true
armas_[arma_nao_segurando].visible = false
func set_(arma):
pass
func shot():
if delay == false:
var instancia : Node = bala_load.instantiate()
instancia.position = global_position
instancia.transform.basis = global_transform.basis
instancia
#instancia.veloz = armas_[arma_segurando]
get_parent().get_parent().get_parent().add_child(instancia)
#spawn_poit = Vector3(0, 0, 0) #arma_segurando.get_node("Marker3D").global_position
#instancia.position = spawn_poit #posicao_de_spawn.global_position
delay = true
$timer_delay.start()