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

Can't get programme working - RP Bundled cables stuff (I think). :(

Started by codecompass, 21 April 2013 - 09:51 AM
codecompass #1
Posted 21 April 2013 - 11:51 AM
Hello everyone, thanks fot taking the time to look at this thread. So here's my situation & Code
I've got a simple elevator that uses frames & Motors, in case you Don't Use RP2 - every time a motor gets a pulse it move the frames in the direction the motor is pointing. I have 2 motors - One hooked up to a ORANGE Insulated cable (up) and one going down to WHITE Insulated cable.

To BLACK Insulated Cable I have hooked up a simple block detector (RS Torch, Repeater and Read Alloy Wire) that simply checks if the frames are on level 1 (To prevent the elevator going down when it's already on lowest level. (Note - the signal is inverted. Dunno why but it seemed easier to wire up.)

I think there may be an error in the BundledCable stuff - This is the second CC project I did using RP Bundled Cables.

The computer runs the programme (startup) but it seems to do bugger all when I press the relevant button (GRAY - up and LIME - down)

I re-written this programme like wat? 3 times by now? I tried functions, repeat until loops and alot of other stuff but I think I'm getting something wrong in the RS-BC API. I'm getting really annoyed that my massive building has no elevator :(/>

while rs.getInput("bottom") == true do –Shut off lever - in case I need to quickly switch it off.

CurrenFloor = nil –Reset Current Floor

if rs.testBundledInput("top", colours.black) == true then CurrenFloor = 2
elseif rs.testBundledInput("top", colours.black) ~= true then CurrenFloor = 1
end

oc = true

while oc == true do
if rs.testBundledInput("top", colours.grey) == true and CurrenFloor == 1 then
for i = 16, 1 do
rs.setBundledOutput("top", colours.add(rs.testBundledInput, colours.orange))
sleep(0.5)
rs.setBundledOutput("top", colours.subtract(rs.testBundledInput, colours.orange))
sleep(0.5)
end
oc = false
i = 0
elseif rs.testBundledInput("top", colours.lime) == true and CurrenFloor == 2 then
for i = 16, 1 do
rs.setBundledOutput("top", colours.add(rs.testBundledInput, colours.white))
sleep(0.5)
rs.setBundledOutput("top", colours.subtract(rs.testBundledInput, colours.white))
sleep(0.5)
end
oc = true
i = 0
end
end
end

Thanks for your help!
Shinjiteru #2
Posted 21 April 2013 - 01:07 PM
Go to the Ask A Pro section for help, this isn't the right place. :P/>
Lyqyd #3
Posted 21 April 2013 - 01:59 PM
Moved to Ask a Pro.

Shinjiteru, please simply report topics which are in the incorrect place in the future. Backseat moderation is discouraged. In this sort of case, telling them to post elsewhere usually results in unnecessary duplicate topics, resulting in more work for the moderators.
Spongy141 #4
Posted 21 April 2013 - 03:37 PM
A few things, one do …. no need to have it in a quote, you should space…. theres no "colors.add" its "colors.combine".
And your making an elevator right?
Most of it will be made with redstone…. Now im guessing you will have more than 2 floors. so try having the computer send a redstone (any color you want) pulse to all the motors on that floor, and all the ones below it, do something like this

term.write("Floor: ")
local floorN = read()
floor = 0
floor = floor + floorN
-- Have each floor number have its own color....
if floor == 2 then  -- Repeat this., like the next one will say 3 not 2.
  rs.setBundledOutput()  -- Fill in the colors ect...
end
You should also loop it… P.S. sometimes if it doesn't work it might be a error between colours and colors.
I'm not sure how effective this will be though, since you'll NEED a different color for every floor, unless you want to a REALLY time consuming redstone stuff….
codecompass #5
Posted 22 April 2013 - 01:51 AM
A few things, one do …. no need to have it in a quote, you should space…. theres no "colors.add" its "colors.combine".
And your making an elevator right?
Most of it will be made with redstone…. Now im guessing you will have more than 2 floors. so try having the computer send a redstone (any color you want) pulse to all the motors on that floor, and all the ones below it, do something like this

term.write("Floor: ")
local floorN = read()
floor = 0
floor = floor + floorN
-- Have each floor number have its own color....
if floor == 2 then  -- Repeat this., like the next one will say 3 not 2.
  rs.setBundledOutput()  -- Fill in the colors ect...
end
You should also loop it… P.S. sometimes if it doesn't work it might be a error between colours and colors.
I'm not sure how effective this will be though, since you'll NEED a different color for every floor, unless you want to a REALLY time consuming redstone stuff….
Thanks, but the lift still does not move. I changed the add to combine but when I press the button it still does'nt move. There are only 2 floors btw - 16 blocks apart

I've written another programme that uses RP BundledCables and I did actually write colour.whatever so It does work. Just not this time :(/>

I've got a screenshot of the motor (the orange one is the same setup - different colour.)



The computer is actually underground so I don't want to type on it - I want to press a button and then it moves.

I'm trying to re-write the code to be shorter (less mistakes!)


while rs.getInput("bottom") == true do
CurrenFloor = nil
if rs.testBundledInput("top", colours.black) == true then CF = 2
elseif rs.testBundledInput("top", colours.black) ~= true then CF = 1
end
oc = true
while oc == true do
if rs.testBundledInput("top", colours.grey) == true and CF == 1 then
  for i = 16, 1 do
	    rs.setBundledOutput("top", colours.orange)
	    sleep(0.5)
	    rs.setBundledOutput("top", colours.subtract(rs.testBundledInput, colours.orange))
	    sleep(0.5)
	   end
	    oc = false
	    i = 0
elseif rs.testBundledInput("top", colours.lime) == true and CF == 2 then
		 for i = 16, 1 do
	    rs.setBundledOutput("top", colours.white)
	    sleep(0.5)
	    rs.setBundledOutput("top", colours.subtract(rs.testBundledInput, colours.white))
		  sleep(0.5)
		 end
	  oc = false
	  i = 0
	  end
   end
end


Trying to cut out as much of the colours API as possible.

Sorry I posted this in the wrong section - classic noob mistake B)/>
Spongy141 #6
Posted 22 April 2013 - 06:26 AM
Oh I see! Hmm… Well How many floors is there?
codecompass #7
Posted 22 April 2013 - 06:51 AM
Oh I see! Hmm… Well How many floors is there?

Just 2 - top one & Ground.
Status Update - replaced
rs.setBundledOutput("top", colours.subtract("ton of code"))
with
rs.setBundledOutput("top", 0)
Spongy141 #8
Posted 22 April 2013 - 07:18 AM
So its button controlled? Well try this.

function detect()
  if rs.getBundledInput("left", colors.green) -- I used green, you can always change it, and the side.
	 rs.setBundledOutput("back", colors.red) -- red is for the top floor.  Blue will be for the bottom.
  end
  if rs.getBundledInput("right", colors.yellow) -- I used yellow, you can always change it, and the side.
	 rs.setBundledOutput("back", colors.blue) -- Blue is for the bottom floor.
  end
end
while true do
  detect()
  sleep(2)
end
Now just wire that up, so one button is green, (Will be at the bottom floor)
And yellow will be on the top floor. Then red will go to the motors… to signal where its stopping point is.
Same with the blue…
theoriginalbit #9
Posted 22 April 2013 - 07:24 AM

if rs.getBundledInput("left", colors.green) -- I used green, you can always change it, and the side.
if rs.getBundledInput("right", colors.yellow) -- I used yellow, you can always change it, and the side.
I think you mean rs.testBundledInput
Spongy141 #10
Posted 22 April 2013 - 07:26 AM

if rs.getBundledInput("left", colors.green) -- I used green, you can always change it, and the side.
if rs.getBundledInput("right", colors.yellow) -- I used yellow, you can always change it, and the side.
I think you mean rs.testBundledInput
Who cares. Lol change it then :P/>, I don't use RP2 with CC anyways.
theoriginalbit #11
Posted 22 April 2013 - 07:31 AM
Who cares. Lol change it then :P/>, I don't use RP2 with CC anyways.
The role of us in the "Ask a Pro" section is to help people, not confuse the asker and/or create more bugs (that aren't caused due to a lack of info from asker)
codecompass #12
Posted 22 April 2013 - 08:26 AM
So its button controlled? Well try this.

function detect()
  if rs.getBundledInput("left", colors.green) -- I used green, you can always change it, and the side.
	 rs.setBundledOutput("back", colors.red) -- red is for the top floor.  Blue will be for the bottom.
  end
  if rs.getBundledInput("right", colors.yellow) -- I used yellow, you can always change it, and the side.
	 rs.setBundledOutput("back", colors.blue) -- Blue is for the bottom floor.
  end
end
while true do
  detect()
  sleep(2)
end
Now just wire that up, so one button is green, (Will be at the bottom floor)
And yellow will be on the top floor. Then red will go to the motors… to signal where its stopping point is.
Same with the blue…

But the problem it I need it to PULSE a certain colour (White down and Orange Up) 16 times- Now I used the
for i = 0, 16, 1
loop thing hoping i would work, now I'm stuck.

Trying out new version (using evil functions as you suggested)

function getPos()
   if rs.testBundledInput("top", colours.black) == true then CF = 2 rs.setOutput("left", false)
   elseif rs.testBundledInput("top", colours.black) ~= true then CF = 1 rs.setOutput("left", true)
   end
end
function getcommand()
   if rs.testBundledInput("top", colours.grey) == true and CF == 1 then cm = up
   elseif rs.testBundledInput("top", colours.lime) == true and CF == 2 then cm = down
   end
end
function up()
for i = 0, 16, 1 do
rs.setBundledOutput("top", 2)
  sleep(1)
  rs.setBundledOutput("top", 0)
  sleep(1)
  end
end
function down()
	for i = 0, 16, 1 do
	rs.setBundledOutput("top", 1)
	sleep(1)
	rs.setBundledOutput("top", 0)
   sleep(1)
   end
end
while rs.getInput("bottom") == true do
CF = nil
getPos()
repeat
getcommand()
until cm ~= nil
if cm = up then up()
elseif cm = down down()
end
cm = nil
end

BTW, the frames work, I tried running the line in lua mode
for i = 0, 16, 1 do rs.setBundledOutput("top", 2) sleep(1) rs.setBundledOutput("top", 0) sleep(1) end
the elevator moved but now want to hook up buttons…
Spongy141 #13
Posted 22 April 2013 - 09:50 AM
Its like you making it over complicated… The "green" and "yellow" in my code was the buttons. so when to pressed it, it would call the elevator.
codecompass #14
Posted 22 April 2013 - 10:24 AM
OK, basically here's a list of all the colours I'm using and what they are meant to do
  • Black - check to see if lift of floor 1 or 2 (ON if 2 OFF if 1)
  • Orange - hooked up to the motor pointing up. Need it to pulse 16 time so that the lift goes up 16 blocks
  • White - motor going down (see orange)
  • Grey - Button on the top floor and 'inside' the lift when it's docked on floor 1 - calls the lift up
  • lime - inverse of grey (calls down)
I try not to make it over complicated it's just that I don't want the lift to 'de-rail' - If someone was to call the lift up when it's on floor 2 it would move but then no motors would be touching the frames so I need that checker to work (black wire)

Essentially I want to build something like this -

[media]http://www.youtube.com/watch?v=I0PorMPuqS8[/media] -

but using CC rather than RedPower computers (I hate FROTH - can't get on with the darn thing)
Spongy141 #15
Posted 22 April 2013 - 03:54 PM
Wow, I tried watching the video, well its too bad I don't speak Russian. Lol, give me some time, I already have it planned out to get it to work, also is this a server thing? If it is, I could go on and get a better look.
EDIT: Well I tried to make a program to make the elevator go up and down, and if it was not at your level, it goes to your level.
Just change back to where the bundled cable goes into the computer. Heres the pastebin link, or copy the code inside the spoiler.
Spoiler


function toTop()
  if rs.testBundledInput("back", colors.black) == true then
    print("Already on top floor, sending back down")
for i = 1,16 do
 rs.setBundledOutput("back", colors.white)
end
  else
    for i = 1,16 do
      rs.setBundledOutput("back", colors.orange)
    end
  end
end
function toBottom()
  if not rs.testBundledInput("back", colors.black) then
    print("Already on bottom floor, sending back up")
for i = 1,16 do
 rs.setBundledOutput("back", colors.orange)
end
   else
    for i = 1,16 do
 rs.setBundledOutput("back", colors.white)
end
  end
end
while true do
  if rs.testBundledInput("back", colors.lime) then
    toBottom()
  end
  if rs.testBundledInput("back", colors.grey) then
    toTop()
  end
end
codecompass #16
Posted 23 April 2013 - 06:39 AM
Thans guys, but today I had a breakthrough and It finally WORKS! :D/>
Here's the screenshot:

In case anyone ever runs into the trouble of creating the code of a RP Frames elevator using bundled wires here's the code -

function getPos()
   if rs.testBundledInput("top", colours.black) == true then CF = 2
   elseif rs.testBundledInput("top", colours.black) ~= true then CF = 1
   end
end
function getcommand()
   if rs.testBundledInput("top", colours.grey) == true and CF == 1 then cm = up
   elseif rs.testBundledInput("top", colours.lime) == true and CF == 2 then cm = down
   end
end
function up()
for i = 0, 16, 1 do
rs.setBundledOutput("top", 2)
  sleep(1)
  rs.setBundledOutput("top", 0)
  sleep(1)
  end
end
function down()
	for i = 0, 16, 1 do
	rs.setBundledOutput("top", 1)
	sleep(1)
	rs.setBundledOutput("top", 0)
   sleep(1)
   end
end
while rs.getInput("bottom") == true do
   CF = nil
	getPos()
  repeat
   getcommand()
   sleep(0)
   until cm ~= nil
   if cm == up then up()
	elseif cm == down then down()
	end
	cm = nil
end

Next logical step would be to add doors but let's not get too ahead of ourselves ;)/>
Lyqyd #17
Posted 23 April 2013 - 07:00 AM

if rs.getBundledInput("left", colors.green) -- I used green, you can always change it, and the side.
if rs.getBundledInput("right", colors.yellow) -- I used yellow, you can always change it, and the side.
I think you mean rs.testBundledInput
Who cares. Lol change it then :P/>/>, I don't use RP2 with CC anyways.

I care. Quality of answers is important here. This sort of cavalier attitude of, "who cares if I get the code in my answer wrong?" is unwelcome here. If you get something wrong, man up and admit you were wrong, correct yourself, and move on. Get it right the next time. It's not hard to make good contributions to Ask a Pro once you have some knowledge under your belt, but bad contributions are not helpful. We're trying to maximize the signal to noise ratio here.
codecompass #18
Posted 23 April 2013 - 11:15 AM
Guys, don't argue. I'm grateful to the guy (Spongy) for suggesting is ideas and fair enough if he doesn't use CC with RP, it's his choice but no need to be all upset about how he's "misleading" and "confusing". Personally I didn't find any of his comments confusing (Just cos I'm new to forums does'nt mean I have never written a CC app before) I just sometimes need help with debugging and I'm grateful to ANYONE who spends their time TRYING to help me (even if they make an error in their correction).
Kye_Duo #19
Posted 24 April 2013 - 02:07 AM
A minor tweak to your program to smooth out your elevator.
the total time between the start of the pulses should be 0.8 as that is how long it takes the frame motor to move the setup. Adjust your program to something like

rs.setBundledOutput("top", 1)
sleep(0.2)
rs.setBundledOutput("top", 0)
sleep (0.6)
and it will smooth out your elevator.
theoriginalbit #20
Posted 24 April 2013 - 02:10 AM
A minor tweak to your program to smooth out your elevator.
the total time between the start of the pulses should be 0.8 as that is how long it takes the frame motor to move the setup. Adjust your program to something like
-snip-
Doesn't really smooth it out, there is still a pause, it just makes the elevator quicker :)/>
And you could make the sleep between the setting to 0.1, since thats the quickest redstone pulse. Then the other time would need to be 0.7… Doesn't make any difference, just a bit of an FYI.
Kye_Duo #21
Posted 24 April 2013 - 02:52 AM
A minor tweak to your program to smooth out your elevator.
the total time between the start of the pulses should be 0.8 as that is how long it takes the frame motor to move the setup. Adjust your program to something like
-snip-
Doesn't really smooth it out, there is still a pause, it just makes the elevator quicker :)/>
And you could make the sleep between the setting to 0.1, since thats the quickest redstone pulse. Then the other time would need to be 0.7… Doesn't make any difference, just a bit of an FYI.
My elevator is smooth with those settings.
theoriginalbit #22
Posted 24 April 2013 - 02:54 AM
My elevator is smooth with those settings.
Maybe I'm just used to servers. Its never smooth on servers even with 0.8 seconds.
Kye_Duo #23
Posted 24 April 2013 - 03:21 AM
My elevator is smooth with those settings.
Maybe I'm just used to servers. Its never smooth on servers even with 0.8 seconds.
this elevator is on a server…but that is the thing with servers. No two are identical.
codecompass #24
Posted 24 April 2013 - 09:15 AM
A minor tweak to your program to smooth out your elevator.
the total time between the start of the pulses should be 0.8 as that is how long it takes the frame motor to move the setup. Adjust your program to something like

rs.setBundledOutput("top", 1)
sleep(0.2)
rs.setBundledOutput("top", 0)
sleep (0.6)
and it will smooth out your elevator.

Thanks! Even slicker now!