Posted 30 March 2013 - 02:57 PM
I'm having a few issues with passing variables as arguments to functions in APIs. Take for example the following program, named testCheck
In the API named check, I have the following code.
For some reason, whenever I run
However, when I run this program:
os.loadAPI("check")
local tArgs = { ... }
var = tonumber(tArgs[1])
if check.positive(var) == false then
print("var must be positive!")
return
end
print("success!")
In the API named check, I have the following code.
local function positive(var)
if var < 0 then
return false
else
return true
end
end
For some reason, whenever I run
testCheck 3
I get the message:
testCheck:4: attempt to call nil
However, when I run this program:
local function positive(var)
if var < 0 then
return false
else
return true
end
end
local tArgs = { ... }
var = tonumber(tArgs[1])
if positive(var) == false then
print("var must be positive!")
return
end
print("success!")
I get the desired result – prints "var must be positive!" if I supply -3 as an argument, and prints "success!" if I give 3 as an argument. The programs are essentially the same, except one uses an API and the other doesn't. So how can I use an API and still get the same result?