Posted 08 September 2013 - 01:51 AM
So exactly what im trying to do is make it where a function can be stored into a table so pretty much something like this. Extremely crude example below.
So i want it so when someone type in "speak" it would use an if statement to check the table find the speak function stored and then executes the function. The reason it need to be a table is because its going to be check for alot more than just for 4 different commands so thought if the if statement could loop through the table wouldn't 100's of elseif statements.
local commands = {talk, sleep, sing, dance} -- table to store the functions
function talk()
print("I talked")
end
function sleep()
print("I slept")
end
function sing()
print("I sung")
end
function dance()
print("I danced")
end
talk = talk()
sleep = sleep()
sing = sing()
dance = dance()
message = read() -- message that would be checked against the table
So i want it so when someone type in "speak" it would use an if statement to check the table find the speak function stored and then executes the function. The reason it need to be a table is because its going to be check for alot more than just for 4 different commands so thought if the if statement could loop through the table wouldn't 100's of elseif statements.