Thread Tools Display Modes
08-25-09, 11:28 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
/commands in xml onclicks

How would you put another addons /command on a button created with xml?

ive tried everything...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
08-25-09, 11:30 PM   #2
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
never mind think i figured it out....
RunSlashCmd("/command")
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
08-30-09, 09:59 AM   #3
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
RunSlashCmd isn't a function provided in the wow api. It's possible to make said function but it's just adding in an unnecessary middle-man.

All slash command handlers are stored in the SlashCmdList table. You just need to find the hash index of the command you want and run it as a function. i.e. if I wanted to call /stopwatch 30


Code:
SlashCmdList['STOPWATCH'](30) -- 30 second timer
  Reply With Quote
08-31-09, 10:11 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Actually.... add this nice little snippet to your lua and what i posted before becomes a valid function...

Also im trying to make calls to other addons slash commands not ones built into wow.

Code:
local function RunSlashCmd(cmd) 
	      local slash, rest = cmd:match("^(%S+)%s*(.-)$") 
	      for name in pairs(SlashCmdList) do 
	         local i = 1 
	         local slashCmd 
	         repeat 
	            slashCmd = _G["SLASH_"..name..i] 
	 
	            if slashCmd == slash then 
	               -- Call the handler  
	               SlashCmdList[name](rest) 
	               return true 
	            end 
	            i = i + 1 
	         until not slashCmd 
	      end 
	    end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 08-31-09 at 10:14 AM.
  Reply With Quote
08-31-09, 02:16 PM   #5
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
All slash commands are stored in the SlashCmdList table, including 3rd party addons.
  Reply With Quote
08-31-09, 05:05 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Waverian View Post
All slash commands are stored in the SlashCmdList table, including 3rd party addons.
You still have to do something like he posted, because the keys of SlashCmdList don't necessarily correspond to the slash command text.
  Reply With Quote
08-31-09, 08:31 PM   #7
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by Akryn View Post
You still have to do something like he posted, because the keys of SlashCmdList don't necessarily correspond to the slash command text.
Most of the indices are pretty obvious, and if they're not you can browse the addon's code. If you need to call a large number of commands then sure, that method is probably fine. If you only need to call one or a few slash command handlers, why wrap it in a function that iterates through the entire table when you you can find the index anyway?

But whatever.
  Reply With Quote
09-01-09, 01:06 AM   #8
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
The question I have is why are you bothering with trying to access the other mod's slash command? All the slash commands do is store a function to the slash. It's an unnecessary step and as you can see is just causing more complications than it's worth. Just call the function and pass any arguments (if any) yourself.

Code:
<OnClick>modFunc(args);</OnClick>
  Reply With Quote
09-01-09, 05:47 AM   #9
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by ChaosInc View Post
The question I have is why are you bothering with trying to access the other mod's slash command? All the slash commands do is store a function to the slash. It's an unnecessary step and as you can see is just causing more complications than it's worth. Just call the function and pass any arguments (if any) yourself.

Code:
<OnClick>modFunc(args);</OnClick>
That depends. Some AddOns don't have to have a global function.
  Reply With Quote
09-01-09, 06:04 AM   #10
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Well the question was "how do you access slash commands" not "how do I access a specific slash command?" -- Just as an example, maybe the button is intended to be configurable by the user.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » /commands in xml onclicks

Thread Tools
Display Modes

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