Originally Posted by kanedax01
Hello, I need some help with an addon I am writing. I want my addon to post the value of a variable, a message, into the chat.
Let's assume I have two variables that contain strings:
hello = "Hey how are you?";
bye = "See you next time!";
The slash command looks like this:
/myaddon say <variable name>
This would be the function. It is incomplete, but I want you to get what I am aiming at.
function MyAddon(param1)
local argT = {};
gsub(param1, "(%S+)", function(w) tinsert(argT, w) end)
if (argT[1] == "say") then
SendChatMessage(argT[2], argT[1], this.language);
end
I want my addon to be able to post the message into different chats depending on the first argument given. In the example above it is "say", but it could also be "party"/"guild"/etc. It sort of works like the Chuck Norris Facts addon, but I don't want random quotes to be posted. The quote posted should be defined by the second argument given by the slash command. I'm using "guild" here as a reference, but it could be any channel.
When typing in "/myaddon guild hello" the chat output should be
[Guild]: Hey how are you?
However, the output is
[Guild]: hello
So basically, it treats the second argument as a string rather than a variable. Can I turn the string into a variable name, or is there another way to post variable names via the slash command?
|
Assuming your variables are global, you can change your SendChatMessage() call's first parameter to be getglobal(argT[2]) instead of just argT[2]