A small rewrite, take what you wish from the code:
Code:
local addonName = ...
local function th(i)
if i > 3 and i < 21 then
return i .. "th"
end
local n = i % 10
if n == 1 then
return i .. "st"
elseif n == 2 then
return i .. "nd"
elseif n == 3 then
return i .. "rd"
end
return i .. "th"
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" and ... == addonName then
-- mySavedVar and charVar should be loaded now - but the names are too vague and other addons might overrite your values, if the other addons are badly coded.
if type(charVar) ~= "number" then
charVar = 0
end
charVar = charVar + 1
if charVar == 1 then
print("Hello " .. UnitName("player") .. ", it's nice to meet you!")
else
print("Hello again " .. UnitName("player") .. ", this is our " .. th(charVar) .. " meeting.")
end
end
end)