Posted 21 September 2016 - 09:50 PM
So I'm working on a sort of "question-answer" program, and I'm having trouble returning variables from a loaded API ("dictionary")
This is the code that's not working in the main program:
And this is the dictionary file:
Now, I'm not sure if I'm just not using "return" right, or if there's something else completely wrong, but I'm sorta at a loss as to why it's not working.
When running the program, it just prints nil.
This is the code that's not working in the main program:
os.loadAPI("AI_dictionary") --[[This loads my dictionary file]]
local input
input=tostring(read())
x=AI_dictionary.handlers(input) --[[This (should) set x equal to the variable returned by my dictionary API]]
print(x) --[[This should just print the variable returned]]
end
And this is the dictionary file:
--[[This handles the input from the main program]]
function handlers(userInput)
response=default
if userInput:lower():find("hello") or userInput:lower():find("hi") then
hello()
end
end
--[[This is the response randomizer]]
function random(y)
local rand=math.random(1,y)
return rand
end
--[[This is the "definition" for hello and it's variants]]
function hello()
local r=random(3)
if r==1 then response="Hi there!" end
if r==2 then response="Hiya!" end
if r==3 then response="Hi "..userName.."!" end --[[This response uses the user's inputted name (which works, and has nothing to do with the problem)]]
return response
end
Now, I'm not sure if I'm just not using "return" right, or if there's something else completely wrong, but I'm sorta at a loss as to why it's not working.
When running the program, it just prints nil.
Edited on 21 September 2016 - 07:51 PM