Need help with this code

local items = {
	
	Sword = {
		Name = "Sword",
		requiredClass = "Warrior",
		requiredLevel = 5,
		Rarity = "Common",
		description = "One Hand\n5-10 Damage\n+5 Stamina",
		--Stats
		damage = {5,10},
		stamina = 5,
		durability = 100,
	},
	Shield = {
		Name = "Shield",
		requiredClass = "Warrior",
		requiredLevel = 1,
		Rarity = "Common",
		--Stats
		armor = 10,
		strength = 5,
		durability = 150,
		--description = "Off Hand\n+"..test.Shield.armor
	},
}

So I’m trying to make descriptions for each item and I’ve been trying to figure out how I can do something like this description = "Off Hand\n+"..Shield.armor.Value.." "..Shield.armor so that the description or the string would look like tihs

Off Hand
+5 Armor

and all I’d have to do is just change the armor value or even better how could I automatically generate the text to do that so if I decided to add like intellect or stamina or remove something the string will automatically adjust to it without having to always update it lol if that’s possible

This doesn’t answer your question but its just a tip. You should use string formatting instead of concatenation because it looks a lot cleaner. Example:

local var = “there”
local var1 = “yes”
Concatenation: print(“Hello " … var … " and " … var1)
String formatting: print((”“Hello %s and %s”):format(var, var1))

^^ In this scenario, when you use string formatting you are basically replacing each %s with a string which you separate with :format.

It works the exact same way but string formatting allows you to not always have to separate words with … And also note there is much more to string formatting then just this with different % / string patterns.

1 Like

Not a Code Review thread. Code Review is only for full code samples that work and that you are looking for specific improvements on, not for prospective help. Use the Scripting Support category if you need specific help on resolving problems with systems.

Recategorised.

My bad I keep forgetting to change that stuff I had a draft and I deleted the text but completely forgot to change the title and category. Is there a setting to disable saving drafts or whatever