Thread Tools Display Modes
06-16-05, 01:18 PM   #1
Coskesh
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
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?
  Reply With Quote
06-17-05, 02:34 AM   #2
Sathanas
A Deviate Faerie Dragon
 
Sathanas's Avatar
AddOn Author - Click to view addons
Join Date: May 2005
Posts: 15
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.
__________________
--Sathanas
  Reply With Quote
06-17-05, 11:08 AM   #3
Coskesh
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
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?
  Reply With Quote
06-17-05, 11:17 AM   #4
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
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

Last edited by Kaelten : 06-17-05 at 11:22 AM.
  Reply With Quote
06-17-05, 11:57 AM   #5
Coskesh
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
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!
  Reply With Quote
06-17-05, 12:09 PM   #6
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
Awesome! glad it helped.
  Reply With Quote
06-18-05, 05:17 AM   #7
greycap
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
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.

Last edited by greycap : 06-18-05 at 05:20 AM.
  Reply With Quote
06-18-05, 09:56 AM   #8
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
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.
__________________
WowAce.com & CurseForge.com Adminstrator
Developer of Ace3, OneBag3, and many other addons and libraries
Project lead and Mac developer for the Curse Client

Anyone that needs what they want
And doesn't want what they need
I want nothing to do with
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problems creating a slash command

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