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.