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

Custom Program Help!

Started by mustbuildhouse, 12 January 2013 - 01:09 PM
mustbuildhouse #1
Posted 12 January 2013 - 02:09 PM
I have another problem with my program, when i enter the password, the computer instantly shutsdown. The password being "hiitsme123". What do I add so it doesn't end and lets me type in the next word being Close/Open? Heres the program:

os.pullEvent = os.pullEventRaw
print ("Welcome To Dam Management. Please enter control center password:")



write ("")
password = io.read()


if password == "hiitsme123" then

print ("Correct. Welcome mustbuildhouse!")
term.clear()
print ("What would you like to do?")
print ("Close Flood Gates")
print ("or")
print ("Open Flood Gates")


write ("")
random = io.read


if random == "Open" then

rs.setBundledOutput("right", colors.white)
sleep(8.0)


elseif command1 == "Close" then

rs.setBundledOutput("right", colors.black)
sleep(8.0)


else

print ("Incorrect. Please exit and try again!")

end

os.shutdown()

end
mustbuildhouse #2
Posted 12 January 2013 - 02:13 PM
where it says random = io.read it really is random = io.read()

nm…i fixed it…
theoriginalbit #3
Posted 12 January 2013 - 02:15 PM
add a loop around the program


while true do
  -- program code
end

Read it wrong (worst thing about no formatting)…. give me a second

Also please try to use [code][/code] tags around your code :)/>
Edited on 12 January 2013 - 01:19 PM
Orwell #4
Posted 12 January 2013 - 02:15 PM
Change:

random = io.read
to:

random = io.read()
:)/> You're skipping the function call there, so 'random' will equal a reference to the io.read function and never math any of the if statements.

Edit: ninja'd
remiX #5
Posted 12 January 2013 - 02:20 PM
Also, before the io.read() add term.clear() and term.setCursorPos(1, 1) so the text doesn't keep going down and down. This will reset the cursor position to the top left.

And, remove the os.shutdown() or else it will still shutdown
ChunLing #6
Posted 12 January 2013 - 05:44 PM
No, I think that part is desired. But move it into the same block as print ("Incorrect. Please exit and try again!") , that way it will only shutdown if the wrong password is entered.

Also, putting a print right before a term.clear() or os.shutdown() is pretty useless, the output doesn't remain onscreen long enough to see unless you have a sleep(1) or a read() or something.
Edited on 12 January 2013 - 04:45 PM