Reply
 
Thread Tools Display Modes
Unread 11-14-12, 01:45 AM   #1
gmarco
A Flamescale Wyrmkin
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 107
Using addon in a macro

Hi all,
I have written a tiny addon that can summon different mounts randomly on categories depending on a custom parameter it will be passed.

The general syntax is

/mrc category1
/mrc category2
etc etc

Now I like to use this addon in a macro so something like:

/mrc [btn:1] category1
/mrc [btn:2] category2

but I suppose I have to use something more than this and probably to modify the addon to add some code to deal with it.

P.s.
The addon discussion and the addon is here:
http://www.wowinterface.com/forums/s...ad.php?t=45113

Thanks for attention.
gmarco is online now   Reply With Quote
Unread 11-14-12, 02:00 AM   #2
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 610
Try /run SlashCmdList["MOUNTRNDCAT"]("category1")
semlar is offline   Reply With Quote
Unread 11-14-12, 04:36 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,030
If you're saying you want to implement macro option parsing for your addon, you can use SecureCmdOptionParse() for this.
Code:
SlashCmdList["MOUNTRNDCAT"] = function(args) 
	local category=SecureCmdOptionParse(args);
	if not category then return; end
	category=category:lower();

	if category=="" then 
		print("MountRandomCategory v.0.2");
		print("Usage: /mrc category");
	elseif mounts[category] then
		if IsMounted() then
			Dismount();
		end

		local number=random(1,#mounts[category]);
		local picked=mounts[category][number]:lower();
		print("casting ...",picked);

		for index=1,GetNumCompanions("MOUNT") do
			local _,name=GetCompanionInfo("MOUNT",index);
			if name:lower()==picked then 
				CallCompanion("MOUNT",index);
			end
		end
	else
		print("MountRandomCategory v.0.2");
		print("Unable to find category",category);
	end
end
I've corrected a few issues, mainly values leaking out into the global namespace that didn't need to be out there. This is controlled by using the local keyword when defining a variable for the first time. I also had the random mount name cached so the CPU wouldn't be used up so much with repetitive indexing of the mounts table.

On a side note, the usage of the underscore as a variable has no special meaning. It's just another valid variable name and is often used as such to shove unwanted values into to fetch values further down the list.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-14-12 at 05:22 PM.
SDPhantom is offline   Reply With Quote
Unread 11-14-12, 05:35 AM   #4
gmarco
A Flamescale Wyrmkin
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 107
Hi,

Thanks really very much for you replies and fixes to my bad code:-)

I'll apply them and try as soon as I return home from work in the afternoon.

Thanks again.
gmarco is online now   Reply With Quote
Unread 11-14-12, 04:46 PM   #5
gmarco
A Flamescale Wyrmkin
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 107
Hi,

It seems to works (almost) everything.

If I create a simple macro like this:

/mrc [btn:1] ground
/mrc [btn:2] flying
... etc etc ...

It works like expected ... button1 cast a ground mount, button2 cast a flying mount but I got an error in bugrabber.

Code:
MountRndCat-0.4\core.lua:11: bad argument #1 to "lower" (string expected, got nil)
<in C code>
MountRndCat-0.4\core.lua:11: in function "?"
FrameXML\ChatFrame.lua:4358: in function "ChatEdit_ParseText"
FrameXML\ChatFrame.lua:4052: in function "ChatEdit_SendText"
FrameXML\ChatFrame.lua:2727: in function <FrameXML\ChatFrame.lua:2720>
<in C code>
FrameXML\SecureTemplates.lua:275: in function "handler"
FrameXML\SecureTemplates.lua:560: in function <FrameXML\SecureTemplates.lua:508>
<in C code>
FrameXML\SecureHandlers.lua:264: in function <FrameXML\SecureHandlers.lua:261>
<in C code>
FrameXML\SecureHandlers.lua:294: in function <FrameXML\SecureHandlers.lua:277>
(tail call): ?

Locals:
args = "[btn:2] flying"
category = nil
The code is this one:

Code:
SLASH_MOUNTRNDCAT1 = "/mntrndcat";
SLASH_MOUNTRNDCAT2 = "/mrc";
SlashCmdList["MOUNTRNDCAT"] = function(args) 
	
	local category=SecureCmdOptionParse(args);
	category = string.lower(category)
	
	if (category == "" ) then 	
		
		print ("MountRandomCategory (mrc for friends)");
		print ("Usage: /mrc your_category\n");	
			
	else	
		
		if(IsMounted()) then
			Dismount();
		end	
		
		local number=random(1,#mounts[category]);
		local picked=mounts[category][number];
	
		print ("mrc is summoning for you: " .. "[" .. category .. "] " .. picked);
		
		-- Protected code
		-- CastSpellByName(mounts[category][number])
		
		-- Non protected code
		for index=1,GetNumCompanions("MOUNT") do
			local _,name=GetCompanionInfo("MOUNT",index);
			if name==picked then 
				CallCompanion("MOUNT",index);
			end
		end
		-- End non protected code
		
	end
	
end
Thanks for your attention.
gmarco is online now   Reply With Quote
Unread 11-14-12, 05:20 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,030
I fixed the code I posted earlier. It appears when none of the conditions match for SecureCmdOptionParse(), it returns nil. At this point, the command should not be run. I added the check for this and have it exit immediately. I also fixed a potential error if the user were to call for a category that doesn't exist. The code is also more robust in the way that both the names in the table and the category name given through the arguments are case-insensitive.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
SDPhantom is offline   Reply With Quote
Reply

Go BackWoWInterface » AddOns, Compilations, Macros » Macro Help » Using addon in a macro

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