I'm trying to expand on to a simple LUA script I wrote (my first time working with LUA) to allow multiple arguments to be passed to it. The problem I'm running into is it seems that the way I'm doing it gives one argument regardless of what I type (I ran into a similar problem when first writing it where the argument wouldn't be nil when nothing was passed to it).
Here's my script:
Code:
import "Turbine"
AhCmd = Turbine.ShellCommand();
function AhCmd:Execute(cmd, arg1, arg2)
if ( type(tonumber(arg1)) == "number" and arg2 == nil ) then
AhCmd:AhCalc(arg1);
elseif ( type(tonumber(arg1)) == "number" and type(tonumber(arg2)) == "number" ) then
AhCmd:AhCalc(arg1, arg2);
else
AhCmd:GetHelp();
end
end
function AhCmd:AhCalc(buyout, bid)
if (bid == nil) then
Turbine.Shell.WriteLine( "<rgb=#00FF00>Set Buyout to</rgb> <rgb=#FFFF00>" .. math.floor( ( buyout/0.95)*(10^2) )/(10^2) .. "s</rgb> <rgb=#00FF00>to get</rgb> <rgb=#80FF00>" .. buyout .. "s</rgb>" );
else
Turbine.Shell.WriteLine( "<rgb=#00FF00>Set Starting Bid to</rgb> <rgb=#FFBF00>" .. math.floor( ( bid/0.95)*(10^2) )/(10^2) .. "s</rgb><rgb=#00FF00>, Buyout to</rgb> <rgb=#FFFF00>" .. math.floor( ( buyout/0.95)*(10^2) )/(10^2) .. "s</rgb> <rgb=#00FF00>to get between</rgb> <rgb=#80FF00>" .. bid .. "s</rgb> <rgb=#00FF00>and</rgb> <rgb=#80FF00>" .. buyout .. "s</rgb>" );
end
end
function AhCmd:GetHelp()
Turbine.Shell.WriteLine( "Syntax: /ah <price>" );
end
Turbine.Shell.AddCommand( "ah", AhCmd );
The script accurately acknowledges 1 argument, but will just return the help text if 2 are is sent.
I know could just add a 2nd command specifically written to accept 2 args, but I really want just 1 command to work for everything