This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mzxs's profile picture

multiple inputs

Started by mzxs, 29 March 2013 - 07:58 AM
mzxs #1
Posted 29 March 2013 - 08:58 AM
ok so i need help i am treing to make it so when i type some thing like a password it can have many options like one to exit one to shutdown and so on how would i do that?
Kingdaro #2
Posted 29 March 2013 - 09:13 AM
Seems pretty simple. You would just need to ask for the password first, while continually checking if it's correct.


local pass = "an amazing password"
local input
while input ~= pass do
  input = read()
  if input ~= pass then
    print 'Access denied.'
  end
end

Then print your options, and wait for a keypress.


print [[
What would you like to do?

1. Exit
2. Shutdown
]]

while true do
  local _, key = os.pullEvent('key')
  if key == '1' then
    break
  elseif key == '2' then
    os.shutdown()
  end
end
mzxs #3
Posted 29 March 2013 - 11:07 AM
ok thanks and i meant more like type commands.
Engineer #4
Posted 29 March 2013 - 11:15 AM
For type commands you would do something like this:

write('write command: ')
local reader = read()
if reader == 'command' then
  --do stuff
elseif reader == 'notetgequotes' then
 -- do stuff
end

you can expand the amount of elseifs.
mzxs #5
Posted 29 March 2013 - 11:37 AM
oh ok so you can put else and if next to each other thanks evern more
mzxs #6
Posted 29 March 2013 - 03:01 PM
hey one more thing im trying to get a image to draw on a monitor using the wires how would i do that?

im doing this

mon0 = peripheral.wrap("monitor_0")

but i dont know how to draw it on it i have ben trying for 2 hours now
Kingdaro #7
Posted 29 March 2013 - 04:51 PM

mon0.write('Some wonderful text!')

And everything else on this page. In your case, replace "term" with "mon0".