The problem comes with deciding how many “parameters” you want to be able to pass/consume on the slash command line. The way I wrote it above accepts 4 (the command (play/run/test), the message to use plus up to 2 others).
The Setup function then assigns the parameters to variables to “merge” into the messages.
Your example added another parameter which needs to be incorporated.
My code breaks the parameters based on finding Space characters in the string passed to the slash command. If it finds a fourth parameter (arg3) it then “re-loads” arg3 with everything after the split for that parameter allowing the last argument to be “free” text with multiple spaces.
The extra parameter in your example needs to be accounted for in the slash command function and how that’s done depends on how you want addon to work (what you are most likely to want to to pass as parameters).
You could change arg3 to another fixed (no spaces) parameter which would work for a date in the xx/xx/xx format but not say, “Dec. 25, 2019”. Effectively the “date” parameter would be an extra no-spaces free text parameter.
Same thing, with slight change (zero “0” will leave a parameter as is)
/ms Parameters:
Command, MessagId, Number(id etc. for functions), NoSpacesText1, NoSpacesText2, FreeText(everything else)
local Pause = 0.5
local Options = {
PAUSE = 0.5,
ARG1 = 169114, -- converts to a number
ARG2 = "NoSpaceText1", -- Text with no spaces
ARG3 = "NoSpaceText2", -- More text with no spaces
ARG4 = "Everything else", -- free text
}
local RunAction
local Messages
local ActionMsg={}
local function Setup(message, number, fixedtext1, fixedtext2, freetext)
if not Messages then
Messages={
RAFFLE={
"-------------",
function() return "Guild Raffle - Ends: " .. Options.ARG3 end,
function() local i = "--== " .. select(2, GetItemInfo(Options.ARG1)) .. " ==--" return i end,
function() return "Worth: " ..Options.ARG2 end,
"-------------",
function() return Options.ARG4 end,
},
MORNIN={
"'Mornin' all",
function() local i = GetSpellLink(Options.ARG1) return "Just woke up ".. i .. " " .. i end,
function() return "What's happenening ".. Options.ARG4 end,
},
RA={
"-------------",
"Guild Raffle",
"--== |cff0070dd|Hitem:169114::::::::112:71::::::|h[Personal Time Displacer]|h|r ==--",
"Worth: 40k gold",
"-------------"
},
MO={
"'Mornin' all",
function() local i = GetSpellLink(Options.ARG1) return "Just woke up ".. i .. " " .. i end,
"What's happenening peoples",
},
}
end
if not Messages[message] then
print("no message named: ", message)
return
end
if number and number ~= "0" then
Options.ARG1 = tonumber(number)
end
if fixedtext1 and fixedtext1 ~= "0" then
Options.ARG2 = fixedtext1
end
if fixedtext2 and fixedtext2 ~= "0" then
Options.ARG3 = fixedtext2
end
if freetext then
Options.ARG4 = freetext
end
ActionMsg = Messages[message]
return true
end
local function Play(msg, line)
print(line, msg)
end
local function Test(msg)
SendChatMessage(msg, "SAY")
end
local function Run(msg)
SendChatMessage(msg, "GUILD")
end
LineNum = 0
local function RunMessage()
LineNum = LineNum + 1
if LineNum > #ActionMsg then
LineNum = 0
return
end
if string.find(tostring(ActionMsg[LineNum]), "function()") then
RunAction(ActionMsg[LineNum](), LineNum)
else
RunAction(ActionMsg[LineNum], LineNum)
end
C_Timer.After(Pause, RunMessage)
end
SLASH_FIZZMESSAGESYNC1 = "/ms"
SlashCmdList["FIZZMESSAGESYNC"] = function(msg)
local command, message, number, fixedtext1, fixedtext2, freetext = string.split(" ", msg)
if freetext then -- add everything that comes "after" fixedtext2 to freetext
freetext = string.sub(msg, string.len(command .. " " .. message .. " " .. number .. " " .. fixedtext1 .. " " .. fixedtext2) + 2)
end
command = string.upper(command)
message = string.upper(message)
if not Setup(message, number, fixedtext1, fixedtext2, freetext) then return end
if command == "PLAY" then
Pause = 0.01
RunAction = Play
elseif command == "TEST" then
Pause = Options.PAUSE
RunAction = Test
elseif command == "RUN" then
Pause = Options.PAUSE
RunAction = Run
else
print("Unknown command:", command)
end
RunMessage()
end
This could be change where the options list is effectively a bunch of replacement parameters which you can use the command line to change (/ms change optionx isnumber New value goes here
) and then just /ms run messageid
over an over until you want to change parameters again.
or you could save the options individually for each message or… I did say this could get elaborate quite quickly
