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

Stop Loop With Bundled Cable

Started by pysko, 30 July 2013 - 05:24 PM
pysko #1
Posted 30 July 2013 - 07:24 PM
Hi i'm new to the forum.

I want to lower a miningplatform and when it hits bedrock it will send a redstone signal. The redstone signal is done and the loop witch lower the platform. what i need is a check for the redstone signal from a gray cable hwo stop the loop lowering the platform and goes to the next loop who rising the platform.

This is just part of the code.

--miner down
for i=1,times do
d=depth
--miner down
redstone.setBundledOutput ("back", 0)
for i=1,depth do
term.clear()
term.setCursorPos(1,1)
print (c, " Cycles left.")
print ("------------------")
print (d, " Blocks left to decend.")
  redstone.setBundledOutput ("back", colors.white)
  sleep (0.2)
  redstone.setBundledOutput ("back", 0)
  sleep (1.5)
d= d-1
end

redstone.setBundledOutput ("back", 0)
d=depth

--miner up
for i=1,depth do
  term.clear()
  term.setCursorPos(1,1)
  print (c, " Cycles left.")
  print ("------------------")
  print (d, " Blocks left to rise.")
  redstone.setBundledOutput ("back", colors.orange)
  sleep (0.2)
  redstone.setBundledOutput ("back", 0)
  sleep (1.5)
  d=d-1
end

I want to change the for loop so it ends when the computer get the redstonesignal insted.
Lyqyd #2
Posted 30 July 2013 - 11:55 PM
Split into new topic.
jesusthekiller #3
Posted 31 July 2013 - 04:44 AM
This will do:


while not colors.test(rs.getBundledInput("back"), colors.gray) do
--#Your code goes here
end
pysko #4
Posted 31 July 2013 - 05:40 AM
Thanks that helpt me alot. I changed it a bit. I wanted the redstone signal to be checked in the end of the loop every time until it was true so i did a while true loop insted. :)/>

Pasting the code so it may help others.

rs.setBundledOutput ("back", 0)

local function pulse (side, nColors)
  local current = rs.getBundledOutput(side)
  rs.setBundledOutput(side, colors.combine(current, nColors))
  sleep(0.2)
  rs.setBundledOutput(side, current)
  sleep(1.5)
end

while true do
  pulse ("back", colors.white)
  if colors.test (rs.getBundledInput ("back"), colors.blue) then
  break
  end
end

for i=0,2 do
pulse ("back",colors.lime)
end

while true do
  pulse ("back", colors.lime)
  if colors.test (rs.getBundledInput ("back"), colors.blue) then
  break
  end
end

The for loop in the midle is to break the redstonesignal before the ramp is risning. I'm new to coding so if anyone feels for it they can post a cleener version of the code if there is one or pinpoint some tips. :)/>

Again many thanks.
jesusthekiller #5
Posted 31 July 2013 - 06:14 AM
if you want check at the end, use

repeat
  --#code here
until <statement>
It works like do while loop