I have a scene that i am using as a Shop Window and i would like to know the best way to set a "Coin" value to each item in my Itemlist,i also have three tabs for the three playable characters in my game but i think i know how to set it so that each one can buy with their own "Coins" i just need to set a value of coin for each Item in the list. i will provide a screenshot of the window and the script so that you might see what i mean.

Maybe use a dictionary to store the cost of each item? Though looking at the code, I think you can refactor/change it to not only make it where you can get the cost of each item, but also make it easier to add/remove items to boot.

I would try using something like this:

extends ItemList

var SHOP_ITEMS = {
	# Swords
	"LongSword":{"sold":false, "type":"Sword", "cost":10},
	"Rapier":{"sold":false, "type":"Sword", "cost":25},
	"Scimitar":{"sold":false, "type":"Sword", "cost":40},
	"BroadSword":{"sold":false, "type":"Sword", "cost":60},
	"BastardSword":{"sold":false, "type":"Sword", "cost":100},
	
	
	# Daggers:
	"RougeDagger":{"sold":false, "type":"Dagger", "cost":10},
	"Shank":{"sold":false, "type":"Dagger", "cost":20},
	"LongKnife":{"sold":false, "type":"Dagger", "cost":30},
	"AssassinBlade":{"sold":false, "type":"Dagger", "cost":50},
	"MurderWeapon":{"sold":false, "type":"Dagger", "cost":80},
}

var selected_item_name = null;

func _ready():
	add_item("Weapon Name", null, false);
	add_item("Weapon Type", null, false);
	add_item("Cost", null, false);
	
	# Add each item.
	for item_name in SHOP_ITEMS:
		add_item(item_name, null, SHOP_ITEMS[item_name]["sold"]);
		add_item(SHOP_ITEMS[item_name]["type"], null, false);
		add_item(str(SHOP_ITEMS[item_name]["cost"]), null, false);
	# Connect the item_selected signal so we know when a item in the list is selected.
	connect("item_selected", self, "shop_item_selected");


func shop_item_selected(index):
	# Get the name of the selected item
	selected_item_name = get_item_text(index);
	# Check if name is a name of a item in the shop (and the type/cost of a item)
	if (SHOP_ITEMS.has(selected_item_name) == true):
		print ("Item selected: ", selected_item_name, " | Cost: ", SHOP_ITEMS[selected_item_name]["cost"]); 
4 years later