Code:
function DCamera_SlashCommandHandler(msg)
local cmd, subCmd = GetCmd(msg);
if (cmd == "show") then
DCamera_SaveFrame:Show();
elseif (cmd == "hide") then
DCamera_SaveFrame:Hide();
elseif (cmd == "save") then
DCamera_SaveView(SubCmd);
else
DCamera_SaveFrame:Show();
end
end
function DCamera_SaveView(msg)
local cmd, subCmd = GetCmd(msg);
if (cmd == "combat") then
combatView = subCmd;
elseif (cmd == "normal") then
normView = subCmd;
elseif (cmd == "mount") then
mountView = subCmd;
else
DEFAULT_CHAT_FRAME:AddMessage("|c00FF00FFDCamera:|r Command Unknown");
end
end
I've screwed something up because when I plug in "/dcam save combat 2" it skips down and goes to message instead of setting the value.|||Is GetCmd defined somewhere? I assume it parses the arguments seperated by strings. One thing I notice:
Code:
local cmd, subCmd = GetCmd(msg);
This line appears in both functions. But in the second function you've only passed one item into it so do you need to do this? When ..._SaveView is called in ..._SlashCommandHandler you're passing SubCmd in. Can't you use this as cmd directly? Or pass the whole message through and reparse it.
What would the result of GetCmd("combat") be? That's what you're doing and I think it's the issue.|||Quote:
Is GetCmd defined somewhere? I assume it parses the arguments seperated by strings. One thing I notice:
Code:
local cmd, subCmd = GetCmd(msg);
This line appears in both functions. But in the second function you've only passed one item into it so do you need to do this? When ..._SaveView is called in ..._SlashCommandHandler you're passing SubCmd in. Can't you use this as cmd directly? Or pass the whole message through and reparse it.
What would the result of GetCmd("combat") be? That's what you're doing and I think it's the issue.
Appreciate the help, but I need it dumbed down a bit. I was just following the advice from wowwiki on this one and never really understood it. I understand normal one arg commands, but from the wiki you have to fiddle with it with more args you add.
From what I understand from the wiki, something like "/dcam show" works fine. But with more arguments it gets trickier and that's where I'm confused. My understanding is:
/dcam save combat 2
First function
cmd = save
subCmd = combat 2
Pass subCmd to second function.
cmd = combat
subCmd = 2
Looking at that it now, it does look wrong and I now see what you're saying about it only passing "combat" and not carrying the "2" with it. So how would I go about fixing it so that it does?
Sorry for the noobish question to what is probably considered an easy concept, but I'm used to working with single commands. Now that I'm trying more complicated things with mods I'm running into things that I'm probably overthinking.|||Since msg is a string containing 'save combat 2' you could use strsplit to parse out the fields.
so entering /dcam save combat 2 in-game
Your code would look like this in your message handler..
Code:
local a, b, c = strsplit(" ", msg)
a would then equal "save"
b would then equal "combat"
c would then equal "2"
Then your code could be similar to this, or whatever you are trying to do.
Code:
if a =="save" then
if b=="combat" then
if c=="2" then
**do something here**
end
end
end
strsplit http://www.wowwiki.com/API_strsplit|||Quote:
Since msg is a string containing 'save combat 2' you could use strsplit to parse out the fields.
so entering /dcam save combat 2 in-game
Your code would look like this in your message handler..
Code:
local a, b, c = strsplit(" ", msg)
a would then equal "save"
b would then equal "combat"
c would then equal "2"
Then your code could be similar to this, or whatever you are trying to do.
Code:
if a =="save" then
if b=="combat" then
if c=="2" then
**do something here**
end
end
end
strsplit http://www.wowwiki.com/API_strsplit
Now that makes sense! Awesome, gonna give that go. Thanks for the help guys!|||Yeah I wasn't entirely sure what GetCmd was doing, but Jumpy's solution is the easiest way to be splitting up the parameters.
No comments:
Post a Comment