Quantcast WoWInterface - View Single Post - Using addon in a macro
View Single Post
11-14-12, 04:36 AM   #3
A Pyroguard Emberseer
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,726
If you're saying you want to implement macro option parsing for your addon, you can use SecureCmdOptionParse() for this.
SlashCmdList["MOUNTRNDCAT"] = function(args) 
	local category=SecureCmdOptionParse(args);
	if not category then return; end

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

		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 
		print("MountRandomCategory v.0.2");
		print("Unable to find category",category);
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.
  Reply With Quote