So I haven't done any Lua work in a while. So I made a chat calculator - because it'd be easy to make.
After finally realizing the only way I could do this was an interface to Google Calculator, I realized I could still do that. And it sort of works. If I do "calculate 2-2" I get 0 like I'm supposed to. But if I do anything else (even put spaces between the numbers and the minus), I get "Invalid Capture Index". That's all it tells me.
Here's the code (I'm sorry there's only one comment):
-- Supplementary Function: The http.Get callback
local function TheCalculatorCallback(result, _)
local jsontable = string.Explode("\"", result)
ULib.tsayColor(nil, true, Color(0,255,0), jsontable[2], Color(255,255,255), " = ", Color(255,255,0), jsontable[4])
end
function ulx.madhouse_calculator( calling_ply, equation )
http.Get("http://www.google.com/ig/calculator?q="..string.gsub(string.gsub(equation,"+", "%2B"), " ", ""), "", TheCalculatorCallback)
end
local calculator = ulx.command( CATEGORY_NAME, "ulx calculate", ulx.madhouse_calculator, "calculate")
calculator:addParam{type=ULib.cmds.StringArg, hint="equation", ULib.cmds.takeRestOfLine}
calculator:defaultAccess(ULib.ACCESS_ALL)
calculator:help("Calculate something, via Google Calculator")
The line it's saying this error is on is the http.Get line. CATEGORY_NAME is defined as "Madhouse" (separate Lua file). The one other command ("loudspeaker", highlights a message with a bunch of red asterisks) works fine.