Godot Version
Godot v4.2.1.stable
Question
the code as of this moment is
extends Node
const Guard = preload("res://assets/characters/guard/guard.gd")
const Guardbullet = preload("res://assets/items/guard_bullet/guard.tscn")
const Explorer = preload("res://assets/characters/explorer/explorer.gd")
var ItemClass = preload("res://assets/inventory/gun.tscn")
var Item = null
var player: Explorer
@onready var inventory_label = $Label
func _ready():
player = get_node("res://assets/characters/explorer/explorer.gd")
if player:
player.connect("inventory_changed", self, "_on_inventory_changed")
func _input(event):
if event is InputEventKey and event.pressed:
if event.keycode == KEY_P:
Item = ItemClass.instance()
add_child(Item)
if event.keycode == KEY_K:
Item.queue_free()
player.change_inventory("gun", -1)
func _process(delta):
pass
func _on_inventory_changed():
var inventory = player.inventory
var inventory_text = ""
for item_name in inventory:
inventory_text += item_name + ": " + str(inventory[item_name]) + "\n"
inventory_label.text = inventory_text
inventory script in the explorer file is
signal inventory_changed()
var inventory = {
"empty_hands" : 1,
"gun" : 0,
"sword" : 0,
"medkit" : 0
}
and also to know which one specifically is selected at the time in the /Explorer.gd script.
var weapons_list = ["gun", "sword","medkit"]
var active_weapon = "empty_hands"
var changing_weapon = false
var weapon_change_timer = Timer.new()
func on_weapon_changed():
changing_weapon = false
i don’t even know if the
player.change_inventory("gun", -1)
will even work. i need a way for it to read specifically gun from the script, or maybe make it do all of them but then i need to load everything into a single script and i don’t know how to do that. this is my 4th iteration of the script and i still do not know how to make it work, i need to first figure out to hit P and it adds the gun to my inventory and with K to remove it, and also understand that the explorer has pickup also physically , cause the keybind is a placeholder for debug testing