how should i set my var, if i have many var but need to choose one?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

how should i set my var, if i have many var but need to choose one?

for example:
when i use item(exmple potion with stats str and con),
i want to increase B_STR["BUFF"] and B_CON["BUFF"]

there any other way to do it? the simple way .

for now i just do like this:
it become so long
inv script

var stats = preload(stats script resource path)
var itemData : Dictionary ={ all data of item}
func _on_invSlot_gui_input(event:InputEvent,invSlot :slotClass):

	if event is InputEventMouseButton:
		if event.button_index == BUTTON_LEFT and event.pressed:
                    stats.update_stats(itemData[statsName], itemData[statsType],itemData[[amount)



              

stats script resource

var B_STR :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}
var B_CON :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}
var B_DEX :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}
var B_INT :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}
var B_WIS :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}
var B_LUK :Dictionary = {"BASE":0,"EQ":0,"BUFF":0,"DEBUFF":0}

func update_stats(statsName,statType,amount):
	match statsName:
		"STR":
                        if statType == "BUFF":
			              B_STR["BUFF"] += amount
                        if statType == "EQ":
			              B_STR["EQ"]+= amount
                        if statType == "BASE":
			              B_STR["BASE"] += amount                
                        if statType == "DEBUFF":
			             B_STR["DEBUFF"] += amount         
		"CON":
                        if statType == "BUFF":
			              B_CON["BUFF"] += amount
                        if statType == "EQ":
			              B_CON["EQ"]+= amount
                        if statType == "BASE":
			               B_CON["BASE"] += amount                
                        if statType == "DEBUFF":
			               B_CON["DEBUFF"] += amount     
		"DEX":
                        if statType == "BUFF":
			               B_DEX["BUFF"] += amount
                        if statType == "EQ":
			               B_DEX["EQ"]+= amount
                        if statType == "BASE":
			              B_DEX["BASE"] += amount                
                        if statType == "DEBUFF":
			             B_DEX["DEBUFF"] += amount 
                         and so on>>>>
:bust_in_silhouette: Reply From: estebanmolca

If I did not misunderstand, do you want to reduce the code?
Dictionaries within dictionaries can be used:

var stats:Dictionary ={
	"B_STR" : {"BASE" : 5, "EQ" : 5, "BUFF" : 5, "DEBUFF" : 5},
	"B_CON" : {"BASE" : 0, "EQ" : 0, "BUFF" : 0, "DEBUFF" : 0},
	"B_DEX" : {"BASE" : 0 ,"EQ" : 0 ,"BUFF" : 0, "DEBUFF" : 0}
}	

func update_stats(stats_name, stat_type, amount):
	stats["B_"+stats_name][stat_type] += amount