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

Elevator problem.

Started by Legless, 13 October 2012 - 04:45 PM
Legless #1
Posted 13 October 2012 - 06:45 PM
So, I've managed to build an elevator (RP-frames). It has 3 floors. There are 2 buttons inside it (Up/Down). 4 colored cables (1,2,4,8) are responsible for buttons. Other 4 (16,32,64,128) are responsible for two pairs of engines. While I was testing a framework of a program, I'd encountered a problem. Cables states aren't changing. Here is the code.

mon = peripheral.wrap("right")
mon.clear()
mon.setCursorPos(1,1)
print("Elevator System")

local wires = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray}
local num = {1, 2, 4, 8, 16, 32, 64, 128, 256}

local function MidUp()
i = 12
repeat
i = i - 1
rs.setBundledOutput("top", colors.combine(rs.setBundledInput("top"), wires[5]))
sleep(0,5)
rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[5]))
sleep(1)
until
i == 0
end

local function UpMid()
i = 12
repeat
i = i - 1
rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[6]))
sleep(0,5)
rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[6]))
sleep(1)
until
i == 0
end


local function DownMid()
i = 12
repeat
i = i - 1
rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[7]))
sleep(0,5)
rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[7]))
sleep(1)
until
i == 0
end

local function MidDown()
i = 12
repeat
i = i - 1
rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[8]))
sleep(0,5)
rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[8]))
sleep(1)
until
i == 0
end


while true do
		local event = os.pullEvent()
		if event == "redstone" and rs.testBundledInput("top", wires[1] == true then
		  print("1")
		  sleep(2)
		  UpMid()
		  sleep(2)
		  print("1 - done")		
		  
		elseif event == "redstone" and rs.testBundledInput("top", wires[2] == true then
		 print("2")
		  sleep(2)
		  MidUp()
		  sleep(2)
		  print("2 - done")	
		  
		elseif event == "redstone" and rs.testBundledInput("top", wires[3] == true then
		 print("3")
		  sleep(2)
		  MidDown()
		  sleep(2)
		  print("3 - done")	
		  
		 elseif event == "redstone" and rs.testBundledInput("top", wires[4] == true then
		 print("4")
		  sleep(2)
		  DownMid()
		  sleep(2)
		  print("4 - done")	
		end
end

Program doesn't show a mistake, it runs up to print("%n% - done").
May be I should replace
rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[8]))
with
rs.setBundledOutput("top", colors.combine(rs.setBundledOutput("top"), wires[8]))
But it writes "Bad argument: int expected, got nil".

I've got stuck. Show me my mistake, please. I have a strong feeling that I am misunderstanding what I've written.
Lyqyd #2
Posted 13 October 2012 - 06:58 PM
In midUp, you have setBundledInput used in the colors.combine; this is incorrect (should be getBundledInput).

In the control loop, you are not closing the parentheses on any of your testBundledInputs.
Legless #3
Posted 13 October 2012 - 07:06 PM
In midUp, you have setBundledInput used in the colors.combine; this is incorrect (should be getBundledInput).

In the control loop, you are not closing the parentheses on any of your testBundledInputs.

My mistake, these things had been already corrected in-game. I pasted a notepad+ version just before it. :)/>/>
Lyqyd #4
Posted 13 October 2012 - 07:24 PM
Please show us the actual code you're using.
Legless #5
Posted 13 October 2012 - 07:34 PM
    mon = peripheral.wrap("right")
    mon.clear()
    mon.setCursorPos(1,1)
    print("Elevator System")
     
    local wires = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray}
    local num = {1, 2, 4, 8, 16, 32, 64, 128, 256}
     
    local function MidUp()
	 i = 12
	 repeat
	 i = i - 1
	 rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[5]))
	 sleep(0,5)
	 rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[5]))
    sleep(1)
	 until
	 i == 0
	 end
     
	 local function UpMid()
	 i = 12
	 repeat
	 i = i - 1
	 rs.setBundledOutput("top", colors.combine(rs.getBundledOutput("top"), wires[6]))
	 sleep(0,5)
	 rs.setBundledOutput("top", colors.subtract(rs.getBundledOutput("top"), wires[6]))
    sleep(1)
	 until
	 i == 0
	 end
     
     
    local function DownMid()
	 i = 12
	 repeat
	 i = i - 1
	 rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[7]))
	 sleep(0,5)
	 rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[7]))
    sleep(1)
	 until
	 i == 0
	 end
     
	 local function MidDown()
	 i = 12
	 repeat
	 i = i - 1
	 rs.setBundledOutput("top", colors.combine(rs.getBundledInput("top"), wires[8]))
	 sleep(0,5)
	 rs.setBundledOutput("top", colors.subtract(rs.getBundledInput("top"), wires[8]))
    sleep(1)
	 until
	 i == 0
	 end
     
     
     
     
     
	 while true do
		    local event = os.pullEvent()
		    if event == "redstone" and rs.testBundledInput("top", wires[1]) == true then
			  print("1")
					  sleep(2)
	    rs.setBundledOutput("top", 0)
	   
					  UpMid()
			  sleep(2)
			  print("1 - done")		    
				     
		    elseif event == "redstone" and rs.testBundledInput("top", wires[2]) == true then
					 print("2")
					  sleep(2)
					  MidUp()
			  sleep(2)
			  print("2 - done")    
				     
				    elseif event == "redstone" and rs.testBundledInput("top", wires[3]) == true then
					 print("3")
					  sleep(2)
					  MidDown()
			  sleep(2)
			  print("3 - done")    
				     
					 elseif event == "redstone" and rs.testBundledInput("top", wires[4]) == true then
					 print("4")
					  sleep(2)
					  DownMid()
			  sleep(2)
			  print("4 - done")    
				    end
    end

Here it is.
Lyqyd #6
Posted 13 October 2012 - 07:39 PM
One thing that could be causing the problem independently of the code is the configuration of wires. Is the wire on top of the computer laying across the top, or does it butt directly up to it? I'm not seeing anything glaringly wrong with the code right now, so this would be the next thing to check.
Legless #7
Posted 13 October 2012 - 07:45 PM
Here is a screenshot. I hope it's a top side. These cables are for visual testing of functions.


I suspect, there is a stupid mistake somewhere.
PixelToast #8
Posted 13 October 2012 - 08:00 PM
there are multiple instances in the sleep function where you used 0,5 instead of 0.5
it only sleeps the first inputs time, so it would reset the inputs instantly
hope i helped :3
Legless #9
Posted 13 October 2012 - 08:12 PM
there are multiple instances in the sleep function where you used 0,5 instead of 0.5
it only sleeps the first inputs time, so it would reset the inputs instantly
hope i helped :3
And of course you DID it!
Thank you guys, as I expected, the mistake was really stupid.
The next tier - to do elevator's call buttons. I'll bump this topic in case of stucking or resolving. Thanks again!