WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Problems creating a slash command (https://www.wowinterface.com/forums/showthread.php?t=996)

Coskesh 06-16-05 01:18 PM

Problems creating a slash command
 
I'm trying to expand on an ingame macro to free up some actionbar space which requires more than the 250 chars.

According to http://www.wowwiki.com/HOWTO:_Create_a_Slash_Command , this is what I have so far:

Code:

function HunterAttack_OnLoad()
        -- Register for Events
        this:RegisterEvent("VARIABLES_LOADED");

        -- Register Slash Commands
        SLASH_HUNTERATTACK1 = "/hunterattack";
        SLASH_HUNTERATTACK2 = "/hatt";
        SlashCmdList["HUNTERATTACK"] = HunterAttack;
        ChatMessage("Coskesh's HunterAttack Loaded.");

end

function HunterAttack(cmd)
        if (IsActionInRange(55)==1) and (IsActionInRange(50)==0) then -- in range for range attack?
                RangedAttack()
        elseif (IsActionInRange(50)==1) then
                MeleeAttack()
        end
end


Ingame, when I call /hatt via a macro, it gives me this:

[sting "Interface\FrameXML\ChatFrame.lua"]:2043: attempt to call local 'value' (a table value).

I tried to check out ChatFrame.lua, but it doesn't exist in that folder. Thoughts?

Sathanas 06-17-05 02:34 AM

Im by no means an expert here, in fact slash commands absolutely drive me insane with their flakey little rules.

But i was having lots of trouble in AggroAlert to get basic slash commands to work, in fact it was just one command to do a toggle just like yours, until i finally cracked it.

I had to add

if (cmd) then

<command handler stuff>

end

inside the function. Again, this might not solve your problem at all, but it solved mine, and mine was set up almost the exact same way.

Coskesh 06-17-05 11:08 AM

Thanks Sathanas.

Still getting that error with your changes.

Can you post your On_Load and your main function so I can have a look?

Kaelten 06-17-05 11:17 AM

Quote:

Originally Posted by Coskesh
I'm trying to expand on an ingame macro to free up some actionbar space which requires more than the 250 chars.

Ingame, when I call /hatt via a macro, it gives me this:

[sting "Interface\FrameXML\ChatFrame.lua"]:2043: attempt to call local 'value' (a table value).

I tried to check out ChatFrame.lua, but it doesn't exist in that folder. Thoughts?



You could check the code in AutoRepair, it has a couple of commands in there.

It looks like, first I didn't setup the chat handler until after the VARIABLES_LOADED event fired.

like this:


Code:

function AutoRepair_OnEvent(event)
        if ( event == "VARIABLES_LOADED" ) then
                AR_Load()
        end

        if ( event == "MERCHANT_SHOW") then
                if (CanMerchantRepair() and AR_Save.enabled) then
                        AR_RepairHandler(false);
                end
        end

end

this was the code I used to set the slash handler

Code:

        SlashCmdList["AUTOREPAIR"] = AR_SlashHandler;
        SLASH_AUTOREPAIR1 = "/autorepair";
        SLASH_AUTOREPAIR2 = "/ar";

And this is the AR_SlashHandler

Code:

function AR_SlashHandler(msg)

  local _,_,command,options = string.find(msg,"([%w%p]+)%s*(.*)$");
       
  if (command) then
          command = string.lower(command);
  end
  if (command == nil or command == "") then
        AR_Chat("Current Settings:");
        AR_Chat("MinCost: ".. WHITE .. setAmountString(AR_Save.minCost));
        AR_Chat("Threshold: " .. WHITE .. setAmountString(AR_Save.costThreshold));
        AR_Chat("Prompts: " .. WHITE .. setEnabledString(AR_Save.promptEnabled));
        AR_Chat("Verbose: " .. WHITE .. setEnabledString(AR_Save.verbose));
        AR_Chat("Skipping Inventory: " .. WHITE .. setEnabledString(AR_Save.skipInv));
        AR_Chat("Available Commands:");
        AR_Chat("/ar MinCost <number>  -- " .. WHITE .."Sets the minimal ammount you wish to ever auto repair for.  This is compared to the total repair costs.");
        AR_Chat("/ar Threshold <number> -- " .. WHITE .."Sets the most your willing to pay for without being prompt.  If your total repair bill is less then your threshold and more than your min. then you'll automatically repair everything.");
        AR_Chat("/ar Prompts -- " .. WHITE .."This toggles showing prompts.  If prompts are disabled Auto Repair will still repair your stuff as long as you can afford it.");
        AR_Chat("/ar Enable -- " .. WHITE .."This turns AutoRepair on and off.");
        AR_Chat("/ar Verbose -- " .. WHITE .. "This toggles showing repair ammounts in the chat area after repair has been done.");
        AR_Chat("/ar SkipInv -- " .. WHITE .. "This toggles skipping inventory check/repair.  If enabled, AR will NOT check your inventory.");

  elseif (command == 'enable')                then AR_EnableHandler();
  elseif (command == 'mincost')        then AR_MinCostHandler(options);
  elseif (command == 'threshold')        then AR_ThresholdHandler(options);
  elseif (command == 'prompt')                then AR_PromptHandler();
  elseif (command == 'verbose')        then AR_VerboseHandler();
  elseif (command == 'skipinv')        then AR_SkipInvHandler();
  end

end


Coskesh 06-17-05 11:57 AM

Hmmm, I move the slash command handler to the top, and renamed my function. Works good now.


Code:

function HunterAttack_OnLoad()
        SlashCmdList["HUNTERATTACK"] = HunterAttack_SlashHandler;
        SLASH_HUNTERATTACK1 = "/hunterattack";
        SLASH_HUNTERATTACK2 = "/hatt";
end

function HunterAttack_SlashHandler()

                if (IsActionInRange(55)==1) and (IsActionInRange(50)==0) then -- in range for range attack?
                        RangedAttack()
                elseif (IsActionInRange(50)==1) then
                        MeleeAttack()
                end
end


Thanks for all the feedback!

Kaelten 06-17-05 12:09 PM

Awesome! glad it helped.

greycap 06-18-05 05:17 AM

I would guess the problem had something to do with :

ChatMessage("Coskesh's HunterAttack Loaded.");


where is that function defined? i dont believe its in the core api.

Kaelten 06-18-05 09:56 AM

could be defined anywhere, even in another mod.

Apprently the problem he had was the placement of the chathandler compared to the / declarations.

Another example of the mystery that is blizzards lua.


All times are GMT -6. The time now is 08:16 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI