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

My castle's drawbridge won't move [SOLVED]

Started by nikojoi, 03 October 2012 - 12:47 AM
nikojoi #1
Posted 03 October 2012 - 02:47 AM
I'm fairly new to programming and cc, but am learning quickly. I've watched tons of videos and gotten a few ideas and pieces of code from the forums before posting, but I still don't know where I am going wrong.

I am trying to write a program to extend or retract a drawbridge. I'm not sure where I am going wrong, when I pulse the cables in the interactive lua command the bridge will move, but it won't with the program.


local function pulse(side, colors, time)
  rs.setBundledOutput(side, colors)
  sleep(time/2)
  rs.setBundledOutput(side, 0)
  sleep(time/2)
end

function open()
  for i=1, 6 do
   pulse("back", colors.orange, 2)
  end
end

function close()
  for i=1, 6 do
   pulse("back", colors.white, 2)
  end
end

function main()
term.clear()
term.setCursorPos(1,1)
write("Open or close ? ")
input = read()
  if input == open then
   open()
  elseif input == close then
   close()
  end
end

main()
Lyqyd #2
Posted 03 October 2012 - 02:57 AM
if input == "open" then, same for close. You'd otherwise be comparing the input against the function itself, rather than a string.
nikojoi #3
Posted 03 October 2012 - 03:57 AM
Thanks ! That was the problem :(/>/>