This is a problem of leaking variables.
When an addon break something which have no relation with the thing which is broken, it's 99% times this.
Here is a better code, even untested
you were leaking
Test, i, out variables.
also please avoid using ";" in lua.
it's accepted, but not recommended for readibility.
I know that 99% of new devs come from php or webdev.. but in this language ";" is not mandatory, just use carriage return
as other good practice, I would
not capitalize var names, but only functions names
avoid t, i, j, k and other tiny names. we're in a world where you have 75% chances that your project will be looked / used / served as reference / rewrited by someone else.
avoid doing
function xxx.yyy() byt only
local function yyy() when this function is not required to be used in another file.
even if for those two, it's my personal choices
Lua Code:
local Test = {
Name = "Test",
Author = "Test",
Version = "1.0"
}
--splits string into array
local function split_str(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
local i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
--Tries to change an item's quality
function Test.GradeItem(text,inc)
--break the string
local item_data = split_str(text,":")
local out = ""
--increment the quality
item_data[4] = tonumber(item_data[4])+inc
if item_data[4] < 0 then
item_data[4] = 0
end
--reassemble
for i = 1, #item_data, 1 do
out = out .. ":" .. item_data[i]
end
--output to chat
CHAT_SYSTEM:AddMessage(out:sub(2))
end
--Grade handlers
local function UpgradeItem(text)
return Test.GradeItem(text,1)
end
local function DowngradeItem(text)
return Test.GradeItem(text,-1)
end
--Tries to upgrade an item's quality
SLASH_COMMANDS["/upitem"] = UpgradeItem
--Tries to downgrade an item's quality
SLASH_COMMANDS["/downitem"] = DowngradeItem