Posted 05 April 2014 - 02:55 AM
So, here is what I have now in my api (relevant anyway), full version can be found here
function prompt(text, ...) --#Improved read() basically, accepts 'valid' input and will keep repeating until it gets a valid answer.
local tArgs = {...}
local tValid = {}
for i = 1, #tArgs do
tValid[tArgs[i]] = true
end
term.write(text..": ")
local input = read()
if tValid[input] or #tArgs == 0 then
return input
else
print("Valid Options:")
for i = 1, #tArgs do
print(tArgs[i])
if i < #tArgs then
term.write("or ")
end
end
return prompt(text, ...)
end
end
function parseColor(input) --#parses input from user into color data
if (colors[input] and type(colors[input]) == "number") or (colours[input] and type(colours[input]) == "number") then
return colors[input] or colours[input]
elseif tonumber(input) then
return tonumber(input)
else
return false
end
end
What I want to do is call prompt in a way as to use the parseColor to make sure they entered a color, then return that color to the program using it. It might look something like this:local mColor = api.prompt("Monitor Color", "color")
Edited on 05 April 2014 - 12:56 AM