Thread Tools Display Modes
06-06-07, 10:39 AM   #1
kanedax01
A Defias Bandit
 
kanedax01's Avatar
Join Date: Jun 2007
Posts: 2
Slash command: Turn String into Variable Name

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?
  Reply With Quote
06-07-07, 10:33 AM   #2
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
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]
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
06-07-07, 06:54 PM   #3
kanedax01
A Defias Bandit
 
kanedax01's Avatar
Join Date: Jun 2007
Posts: 2
Yay, it worked.

Thank you very much for your help!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Slash command: Turn String into Variable Name


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off