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

Watergate Not working

Started by Moulton, 26 May 2014 - 04:03 PM
Moulton #1
Posted 26 May 2014 - 06:03 PM
Note* this is my first ever script
Basically I wanted my script to state if the redstone is on or off, then ask the user if they wish to turn it on.
http://pastebin.com/fDQjpUL3
trouble is when i tried fixing it, it asked for the yes phrase or no phrase before printing anything :(/>
please help?
Seeker14491 #2
Posted 26 May 2014 - 09:33 PM
I found a few mistakes:
line 12: should be "if redstone.getOutput("back") then" instead of "if redstone.getOutput("back",true) then"
line 29: delete "then"
line 41: delete "end"
line 43: delete the " after false and the "end" at the end
all places in the code where you have "input" it should be "read()" (with parenthesis). "input" is not a function, and you need parenthesis to actually call the function.
setCursorPos only uses whole numbers

Also, because of this code,

local Yes = "Yes, yes"
local No = "No, no"
the user has to answer exactly either "Yes, yes" or "No, no". I think what you where trying to do was have the program accept lowercase or uppercase "yes" and "no", but it won't work like that. There are many ways to fix this, look below for one way I fixed it.

Here is the fully fixed version, which I tested and seems to work perfectly:

local ANSWERS = {Yes = true, yes = true, No = false, no = false}
local monitor = peripheral.wrap("right")
monitor.clear()
monitor.setTextScale(2)
monitor.setCursorPos(3,3)
monitor.write("Waterflow:")
while true do
  term.clear()
  term.setCursorPos(1,1)
  print("Waterflow:")
  if redstone.getOutput("back") then
    print(" On")
    monitor.setCursorPos(4,4)
    monitor.clearLine()
    monitor.write("Released")
    term.setCursorPos(1,3)
    term.clearLine()
    print("Do you want to stop the flow?")
    local response = ANSWERS[read()]
    if response then
	  redstone.setOutput("back",false)
	  monitor.setCursorPos(3,4)
	  monitor.clearLine()
	  monitor.write("Unreleased")
    elseif response == false then
	  redstone.setOutput("back", true)
    end 
  else
    print(" Off")
    monitor.setCursorPos(3,4)
    monitor.clearLine()
    monitor.write("Unreleased")
    term.setCursorPos(1,3)
    term.clearLine()
    print("Do you want to turn on the flow?")
    local response = ANSWERS[read()]
    if response then
	  redstone.setOutput("back",true)
	  monitor.setCursorPos(4,4)
	  monitor.clearLine()
	  monitor.write("Released")
    elseif response == false then
	  redstone.setOutput("back", false)
    end 
  end
end