44 posts
Posted 01 October 2014 - 03:26 PM
Again, I'm stuck. I was testing my code and whenever I was typing something into it (like a password, anything i typed in), it didn't do anything unless i retyped it. for example i would type 12345, enter, 12345, enter, for it to work. Here is the code, and thanks for your help!
http://pastebin.com/UnVkVL8v
5 posts
Posted 01 October 2014 - 03:49 PM
I'm guessing it's because you're calling read() once for every conditional in your if statements. You should only call it once any time you want the user to input something, storing the result in a variable and using the value of that in your conditionals (like you do for the initial command).
As an example, change this:
if read() == "on" then
term.setTextColor(colors.lime)
print("Power coming ONLINE")
rednet.send(INSERT16, "powereon")
term.setTextColor(colors.white)
elseif read() == "off" then
term.setTextColor(colors.red)
print("Power going OFFLINE")
rednet.send(INSERT16, "poweroff")
term.setTextColor(colors.white)
else
print("Invalid. Accepted Commands: on, off.")
end
To this:
local input = read()
if input == "on" then
term.setTextColor(colors.lime)
print("Power coming ONLINE")
rednet.send(INSERT16, "powereon")
term.setTextColor(colors.white)
elseif input == "off" then
term.setTextColor(colors.red)
print("Power going OFFLINE")
rednet.send(INSERT16, "poweroff")
term.setTextColor(colors.white)
else
print("Invalid. Accepted Commands: on, off.")
end
1852 posts
Location
Sweden
Posted 01 October 2014 - 03:51 PM
Because you're doing this
if read() == "something" then
...
elseif read() == "something_else" then
...
end
it calls read again.
Try assigning it to a variable instead and use that for checking
local command = read()
if command == "fc" then
local password = read( "*" )
if password == "Password" then
local input = read()
if input == "on" then
...
elseif input == "off" then
...
end
end
end
44 posts
Posted 01 October 2014 - 03:52 PM
Thanks!