53 posts
Location
Yes. (Location does mean wanted in 12 countries, right?)
Posted 29 July 2015 - 03:34 AM
I'm making a text based game where you input commands to control your player. i want certain commands to require arguments, but i cant figure out how to do that. i dont want to have hundreds of commands that all will use a different item, i want one command that will do something different based on the argument you give it (ex. "use (item)"). Thanks in advance :)/>
3057 posts
Location
United States of America
Posted 29 July 2015 - 03:57 AM
So… something like this? It'll return two things: a command (eg "use") and a table of arguments (eg {"item"}).
local function prompt()
local args = {}
for arg in read():gmatch( "%S+" ) do
args[ #args + 1 ] = arg
end
return table.remove( args, 1 ), args
end
Patterns are your friend… You should learn them!
53 posts
Location
Yes. (Location does mean wanted in 12 countries, right?)
Posted 29 July 2015 - 04:35 AM
It confused me a little at first, but i figured out how it works. thanks for the help :)/>