View Single Post
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: 2,326
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.
__________________
WoWInterface AddOns
"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