Thread Tools Display Modes
12-10-06, 11:53 AM   #1
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
How do I add args to /commands.

Been teaching myself how to make addons with some help from folks on the official WoW Ui forums. I've run into a roadblock though so I figured I'd come here.

I found a resource for creating a slash command and I've got it working but it's also pretty much global. I've basically got 120 buttons on my screen now, created an overlay frame for each one that is movable and drags the button along with it.

The slash commands currently look like this:

Code:
SlashCmdList["ColonelBarCOMMAND"] = 
function(msg) 
    if strlower(strtrim(msg)) == "move" then
        for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Show()
        end
    elseif strlower(strtrim(msg)) == "lock" then
        for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Hide()
        end
    end
end
SLASH_ColonelBarCOMMAND1 = "/eb"
SLASH_ColonelBarCOMMAND2 = "/easybar"
Now, that just turns on the 'cap' basically and turns it off but it does it for all 120 buttons. I can't find anything that tells me how to create an arguement in a slash command so I figured I'd come here and ask

I basically want to make it so I can move or lock individual buttons, right nwo I don't mind having to do them all individually, I'll work on grouping later.

Thanks in advance for any help you folks can offer.
  Reply With Quote
12-10-06, 01:47 PM   #2
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Ok, I figured a ghetto work around :P

Code:
SlashCmdList["ColonelBarCOMMAND"] = 
function(input) 
    if (input) == "move1" then
              getglobal("EasyBarButton1Cap"):Show()
    elseif (input) == "lock1" then
              getglobal("EasyBarButton1Cap"):Hide()
    end
    if (input) == "move2" then
              getglobal("EasyBarButton2Cap"):Show()
    elseif (input) == "lock2" then
              getglobal("EasyBarButton2Cap"):Hide()
    end
    if (input) == "move3" then
              getglobal("EasyBarButton3Cap"):Show()
    elseif (input) == "lock3" then
              getglobal("EasyBarButton3Cap"):Hide()
    end
    if (input) == "move4" then
              getglobal("EasyBarButton4Cap"):Show()
    elseif (input) == "lock4" then
              getglobal("EasyBarButton4Cap"):Hide()
    end
    if (input) == "move5" then
              getglobal("EasyBarButton5Cap"):Show()
    elseif (input) == "lock5" then
              getglobal("EasyBarButton5Cap"):Hide()
    end
    if (input) == "move6" then
              getglobal("EasyBarButton6Cap"):Show()
    elseif (input) == "lock6" then
              getglobal("EasyBarButton6Cap"):Hide()
    end
    if (input) == "move7" then
              getglobal("EasyBarButton7Cap"):Show()
    elseif (input) == "lock7" then
              getglobal("EasyBarButton7Cap"):Hide()
    end
    if (input) == "move8" then
              getglobal("EasyBarButton8Cap"):Show()
    elseif (input) == "lock8" then
              getglobal("EasyBarButton8Cap"):Hide()
    end
    if (input) == "move9" then
              getglobal("EasyBarButton9Cap"):Show()
    elseif (input) == "lock9" then
              getglobal("EasyBarButton9Cap"):Hide()
    end
    if (input) == "move10" then
              getglobal("EasyBarButton10Cap"):Show()
    elseif (input) == "lock10" then
              getglobal("EasyBarButton10Cap"):Hide()
    end
    if (input) == "move" then
    	for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Show()
        end
    elseif (input) == "lock" then
    	for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Hide()
        end
    end
end
SLASH_ColonelBarCOMMAND1 = "/eb"
SLASH_ColonelBarCOMMAND2 = "/easybar"
As you can probably see, I basically made an individual if/else for each button individually. It's a bit backwards considering I dynamically generate all my buttons with math but I can't figure out how to add an arguement to my slash command lol. Either way, right now /eb moveX (x = the action ID) and /eb lockX will move/lock individual buttons and /eb lock /eb move will lock/move the entire set. (toggle)

In the final command it uses "for i = 1, 120 do" to isolate "i" which is defined by the action ID earlier in my code and that line enables me to type /eb move to include every button from 1-120, I have no idea how to make my slash command accept another arguement for say /eb move 1 and reference that i to determine which button to move.
  Reply With Quote
12-10-06, 06:14 PM   #3
Karrion
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 23
You should use a regular expression to parse the argument(s). For example:
Code:
local _, _, num =  string.find(input, "move%s*(%d+)");
if (num) then
    -- matched "move <num>"
    getglobal("EasyBarButton"..num.."Cap"):Show();
end
  Reply With Quote
12-10-06, 06:21 PM   #4
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Originally Posted by Karrion
You should use a regular expression to parse the argument(s). For example:
Code:
local _, _, num =  string.find(input, "move%s*(%d+)");
if (num) then
    -- matched "move <num>"
    getglobal("EasyBarButton"..num.."Cap"):Show();
end
Ok, I'm pretty much a complete coding newb, I'm doign this to teach myself how basically... could you give me a little detail on what that does and how I'd add that to my stuff or replace my stuff with that.

I need to tie the variable to the 'move' arguement so I can type /eb move <num> If what you mentioned does that and I'm just not getting it, I'm sorry.. like I said, total newb here heh.
  Reply With Quote
12-10-06, 07:33 PM   #5
Sent_
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 6
May I suggest something like this
Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "a") then
		--do stuff

	elseif (argT[1] == "b") then
		--do other stuff

	end
end
If you type somethink like
/yourmod a b c
argT[1] will contain a
argT[2] will contain b
argT[3] will contain c
  Reply With Quote
12-10-06, 08:58 PM   #6
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Originally Posted by Sent_
May I suggest something like this
Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "a") then
		--do stuff

	elseif (argT[1] == "b") then
		--do other stuff

	end
end
If you type somethink like
/yourmod a b c
argT[1] will contain a
argT[2] will contain b
argT[3] will contain c
I'm getting there soon, the problem isn't the different 'stuff' to do, its telling it to do it to one of 120 different individual buttons.

Right now I can do lots of stuff to all 120 at the same time, but I can't do anything to 1 at a time without making A LOT of text entries (read above, basically recreating each command for every single button)

I will use that arg 1, 2, 3 thing though thats my next step, I gotta figure out hwo to do 1 thing to 120 items individually first though.
  Reply With Quote
12-11-06, 05:08 AM   #7
Sent_
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 6
Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                  --argT[2] checks here
		getglobal("EasyBarButton"..argT[2].."Cap"):Show();

         elseif..........
?
  Reply With Quote
12-11-06, 06:40 AM   #8
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Originally Posted by Sent_
Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                  --argT[2] checks here
		getglobal("EasyBarButton"..argT[2].."Cap"):Show();

         elseif..........
?
I guess I just don't 'get' it. Like I said above I'm new. Going to look up some of the stuff in code in the lua manual and hopefully it'll dawn on me what you're suggesting

Thanks for the help! Hopefully I'll have enough free time at work today to look it up so I can try it out when I get home heh.
  Reply With Quote
12-11-06, 08:40 PM   #9
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Yeah, I'm just too green at this stuff to get what you're tryin to do there.

I'm going to move on to easier concepts for now. Thanks for thsoe that replied, if you find time to go into a little more detail or would like more detail from me I can do a full code dump, its fairly small right now from start to finish. Anything to further my learning otherwise, thanks and hopefuly I'm not too annoying with my future posts lol.
  Reply With Quote
12-11-06, 09:56 PM   #10
ayradyss
A Theradrim Guardian
 
ayradyss's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 68
Just a little clarification...

Code:
local _, _, num =  string.find(input, "move%s*(%d+)");
if (num) then
    -- matched "move <num>"
    getglobal("EasyBarButton"..num.."Cap"):Show();
end
If this is the stuff that's causing you distress, let me break it down a bit.
(Read http://www.regular-expressions.info/tutorial.html for some basic lessons on regex, which is hard to understand at first but quickly becomes very useful)
Basically, line 1 takes your '/eb move 1' and strips out the number - assigning it to 'num'.
(%d+) translates to "capture all numbers", simplistically.

Now you know which number button you're moving, and you plug it in to the getglobal just like you would with a 'for' statement.

Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                  --argT[2] checks here
		getglobal("EasyBarButton"..argT[2].."Cap"):Show();
is an extension of the same idea. string.gsub is pretty powerful, and takes a lot of explaining. Basically, this makes a table of your arguments - so '/eb move 2' now becomes {"move", "2"} and you can use each argument as you choose.


Is any of that helpful?
  Reply With Quote
12-11-06, 10:32 PM   #11
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Originally Posted by ayradyss
Code:
local _, _, num =  string.find(input, "move%s*(%d+)");
if (num) then
    -- matched "move <num>"
    getglobal("EasyBarButton"..num.."Cap"):Show();
end
If this is the stuff that's causing you distress, let me break it down a bit.
(Read http://www.regular-expressions.info/tutorial.html for some basic lessons on regex, which is hard to understand at first but quickly becomes very useful)
Basically, line 1 takes your '/eb move 1' and strips out the number - assigning it to 'num'.
(%d+) translates to "capture all numbers", simplistically.

Now you know which number button you're moving, and you plug it in to the getglobal just like you would with a 'for' statement.

Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                  --argT[2] checks here
		getglobal("EasyBarButton"..argT[2].."Cap"):Show();
is an extension of the same idea. string.gsub is pretty powerful, and takes a lot of explaining. Basically, this makes a table of your arguments - so '/eb move 2' now becomes {"move", "2"} and you can use each argument as you choose.


Is any of that helpful?
If I hadn't been drinking I bet it would be really helpful. I'm going to sleep this off and try to come up with soem code tomorrow at work. I'll post here with what I think will work based on what you fine folks have offered up.

I appreciate the help and patience greatly!
  Reply With Quote
12-12-06, 07:30 PM   #12
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Originally Posted by ayradyss
Code:
local _, _, num =  string.find(input, "move%s*(%d+)");
if (num) then
    -- matched "move <num>"
    getglobal("EasyBarButton"..num.."Cap"):Show();
end
If this is the stuff that's causing you distress, let me break it down a bit.
(Read http://www.regular-expressions.info/tutorial.html for some basic lessons on regex, which is hard to understand at first but quickly becomes very useful)
Basically, line 1 takes your '/eb move 1' and strips out the number - assigning it to 'num'.
(%d+) translates to "capture all numbers", simplistically.

Now you know which number button you're moving, and you plug it in to the getglobal just like you would with a 'for' statement.

Code:
function Handler(text)
	local argT = {};
	gsub(text, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                  --argT[2] checks here
		getglobal("EasyBarButton"..argT[2].."Cap"):Show();
is an extension of the same idea. string.gsub is pretty powerful, and takes a lot of explaining. Basically, this makes a table of your arguments - so '/eb move 2' now becomes {"move", "2"} and you can use each argument as you choose.


Is any of that helpful?

I cant figure out any way to put in either of those with the slash command list without it freaking out and giving me an unexpected character error =\

I hate being a newb at this.
  Reply With Quote
12-12-06, 07:45 PM   #13
ayradyss
A Theradrim Guardian
 
ayradyss's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 68
Code:
SlashCmdList["ColonelBarCOMMAND"] = 
function(msg) 
    if strlower(strtrim(msg)) == "move" then
        for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Show()
        end
    elseif strlower(strtrim(msg)) == "lock" then
        for i = 1, 120 do
              getglobal("EasyBarButton"..i.."Cap"):Hide()
        end
    end
end
SLASH_ColonelBarCOMMAND1 = "/eb"
SLASH_ColonelBarCOMMAND2 = "/easybar"
Subsequently should become something like...

Code:
SlashCmdList["ColonelBarCOMMAND"] = 
function(msg) 
	local argT = {};
	gsub(msg, "(%S+)", function(w) tinsert(argT, w) end)

	if (argT[1] == "show") then
                if tonum(argT[2]) > 0 then 
			getglobal("EasyBarButton"..argT[2].."Cap"):Show();
		end
	elseif (argT[1]) == "move" then
                if tonum(argT[2]) > 0 then 
			getglobal("EasyBarButton"..argT[2].."Cap"):Move();
		end
	end
end
SLASH_ColonelBarCOMMAND1 = "/eb"
SLASH_ColonelBarCOMMAND2 = "/easybar"
Does that make sense?
  Reply With Quote
12-12-06, 10:10 PM   #14
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Subsequently should become something like...

Code:
snipped to save space since its right above this post.
Does that make sense?
I get the concept but it's not working.


This is what I have .


Code:
SlashCmdList["ColonelBarCOMMAND"] = 
function (msg)	
	local argT = {};
	gsub(msg, "(%S+)", function(w) tinsert(argT, w) end)
	if (argT[1]) == "move" then
		if tonum(argT[2]) > 0 then
			getglobal("EasyBarButton"..argT[2].."Cap"):Show();
		end
	else if (argT[1]) == "lock" then
		if tonum(argT[2]) > 0 then
			getglobal("EasybarButton"..argT[2].."Cap"):Hide();
		end
	end
end	
end

SLASH_ColonelBarCOMMAND1 = "/eb"
SLASH_ColonelBarCOMMAND2 = "/easybar"
This is the error I get.

\interface\addons\easybar\EasyBar.lua:54: attempt to call global 'tonum' (a nil value)


so I removed 'tonum' thinking it was just an artifact of you trying to explain something to me and it gave me a whole new error.

btw, I really appreciate the help, I know I keep saying that but this is really interesting to me and the way I learn things is to flounder about at first and once I get 1 working 'thing' in whatever I'm tryin to learn I can build off that and teach myself so this is helping me a lot.
  Reply With Quote
12-13-06, 04:58 AM   #15
ayradyss
A Theradrim Guardian
 
ayradyss's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 68
My bad.
Try 'tonumber' instead of 'tonum' - wrong coding language for a tick there.

Incidentally, what are you using to do your coding in? Hopefully something with syntax support.

Last edited by ayradyss : 12-13-06 at 05:00 AM.
  Reply With Quote
12-13-06, 06:55 AM   #16
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
Talking

Originally Posted by ayradyss
My bad.
Try 'tonumber' instead of 'tonum' - wrong coding language for a tick there.

Incidentally, what are you using to do your coding in? Hopefully something with syntax support.

At first it was notepad Now I'm using Blua.

fyi, it worked and I love you. and I learned some stuff!

Thank you very much.

Now I should be able to extend the command to do button hiding on top of the cap hiding and hopefully figure out scaling by command as well ))
  Reply With Quote
12-13-06, 10:33 AM   #17
Kiphere
A Deviate Faerie Dragon
Join Date: Dec 2006
Posts: 17
I just wanted to add, outside of some minor cosmetic things, you guys helped me finish my first 'complete' mod with these suggestions Thank you so very much.

I've got 120 individual hotkeys that I can move, lock, and hide. I'm going to add in scaling today but I honestly don't anticipate it being that hard with what I've got base wise.

Thanks again, hopefully I'll be able to add something to the community other than questions soon
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do I add args to /commands.


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