Godot Version
Godot 4.5
Question
Hey there, I’ve been working on a JRPG system for months now, and currently, I’m having this issue with the pause menu. Like any other JRPG, it has a menu for the items and equipments, and I’ve made a function that is supposed to refresh the lists and create buttons for them if they’re pressed.
But for some reason, any time this function is called, it’ll make duplicate buttons for every piece of equipment, doesn’t matter if it’s by a button press or if it’s in the _ready function, I keep getting the same result. It still works as intended, but I want to remove those duplicated equiment buttons.
I tried looking into the function’s code to see if there’s anything that could be causing it, but so far, my mind has been a blank and I don’t know what’s causing it. If anyone could help me, it would be appreciated as I’m still a bit of an amateur.
func refreshEquipmentList():
if InventorySystem.equipment:
print(InventorySystem.equipment)
for i in (InventorySystem.equipment.size() - 1):
#Creates the button and its properties
var button = Button.new()
button.text = str(InventorySystem.equipment[i].Resource.name) + " " + str(InventorySystem.equipment[i].quantity)
button.custom_minimum_size.y = 80
button.alignment = HORIZONTAL_ALIGNMENT_LEFT
button.icon = InventorySystem.equipment[i].Resource.icon
button.expand_icon = true
button.theme = preload("res://Themes/theme.tres")
#Connects the buttons to the appropriate signals.
button.focus_entered.connect(showEquipmentDescription.bind(InventorySystem.equipment[i].Resource.description, button))
button.focus_entered.connect(showFinalStats.bind(InventorySystem.equipment[i].Resource))
button.focus_exited.connect(emptyDescription)
#Checks the equipment resource type and the accessory number to determine which menu it'll be added and which slot that resource will take.
if InventorySystem.equipment[i].Resource.type == "Grimoire Charm":
button.pressed.connect(GameManager.activeParty[0].equip.bind(InventorySystem.equipment[i].Resource, GameManager.activeParty[0].WeaponTypeName))
button.pressed.connect(hideMenus.bind(0))
WeaponsList.add_child(button)
elif InventorySystem.equipment[i].Resource.type == "Accessory":
match AccessoryNo:
0:
button.pressed.connect(GameManager.activeParty[0].equip.bind(InventorySystem.equipment[i].Resource, \
"Accessory 1"))
1:
button.pressed.connect(GameManager.activeParty[0].equip.bind(InventorySystem.equipment[i].Resource, \
"Accessory 2"))
button.pressed.connect(hideMenus.bind(1))
button.pressed.connect(showEvaStats)
AccessoryList.add_child(button)
print("Button added")
print(i)
I apologize if this doesn’t look too clean, as this is my first time trying to typing code-related stuff here, and I still haven’t refactored my code. But in general, any help with this function would be appreciated

