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

simple repeater program?

Started by Cranium, 21 July 2012 - 04:13 PM
Cranium #1
Posted 21 July 2012 - 06:13 PM
I have been trying to set up a train system with CC, but have yet been unable to set up any successful repeaters, since the redstone current only goes so far with the Bundled Cable. I have tried setting up computers at set intervals to receive the incoming Bundled Cable input, and then if on or off, repeat that signal on the other side. So far, I can't do that. As far as I know, the variables I'm setting are not returning a "true/false" statement when executing my original function. I'm really new to programming, so I need to know why they are not repeating.
Code here:

function setOutput(side,col,vif)
if vif == true then
  rs.setBundledOutput(side,col)
  sleep(1)
if vif == false then
  rs.setBundledOutput(side,colors.white)
  sleep(1)
end
b =(colors.test (redstone.getBundledInput("right"), colors.orange))
c =(colors.test (redstone.getBundledInput("right"), colors.magenta))
d =(colors.test (redstone.getBundledInput("right"), colors.lightBlue))
e =(colors.test (redstone.getBundledInput("right"), colors.yellow))
f =(colors.test (redstone.getBundledInput("right"), colors.lime))
g =(colors.test (redstone.getBundledInput("right"), colors.pink))
h =(colors.test (redstone.getBundledInput("right"), colors.gray))
i =(colors.test (redstone.getBundledInput("right"), colors.lightGray))
j =(colors.test (redstone.getBundledInput("right"), colors.cyan))
k =(colors.test (redstone.getBundledInput("right"), colors.purple))
l =(colors.test (redstone.getBundledInput("right"), colors.blue))
m =(colors.test (redstone.getBundledInput("right"), colors.brown))
n =(colors.test (redstone.getBundledInput("right"), colors.green))
o =(colors.test (redstone.getBundledInput("right"), colors.red))
p =(colors.test (redstone.getBundledInput("right"), colors.black))
z =(rs.testBundledInput("right",red))
setOutput("left",colors.orange,:)/>/>
setOutput("left",colors.magenta,c)
setOutput("left",colors.lightBlue,d)
setOutput("left",colors.yellow,e)
setOutput("left",colors.lime,f)
setOutput("left",colors.pink,g)
setOutput("left",colors.gray,h)
setOutput("left",colors.lightGray,i)
setOutput("left",colors.cyan,j)
setOutput("left",colors.purple,k)
setOutput("left",colors.blue,l)
setOutput("left",colors.brown,m)
setOutput("left",colors.green,n )
setOutput("left",colors.red,o)
setOutput("left",colors.black,p)
end
end
Sxw #2
Posted 21 July 2012 - 06:34 PM
I cant test it ATM but i think you need to combine all colors with color.combine, sorry i cant be much help, but i should get my laptop back yet again later today.
Cranium #3
Posted 21 July 2012 - 07:00 PM
I fixed all of my variables to spit out a proper output(true/false), by moving them ABOVE my function, but now my function doesn't….well, FUNCTION!
Renamed my variables for easier identification, but still no results. it's as if the function is not properly reading my while/do statement. This is probably just a syntax thing, but again, I'm illiterate in code, and kinda bumping around in the dark.

-- vars
whitecheck =(colors.test (rs.getBundledInput("right"), colors.white))
orangecheck =(colors.test (rs.getBundledInput("right"), colors.orange))
magentacheck =(colors.test (rs.getBundledInput("right"), colors.magenta))
lightBluecheck =(colors.test (rs.getBundledInput("right"), colors.lightBlue))
yellowcheck =(colors.test (rs.getBundledInput("right"), colors.yellow))
limecheck =(colors.test (rs.getBundledInput("right"), colors.lime))
pinkcheck =(colors.test (rs.getBundledInput("right"), colors.pink))
graycheck =(colors.test (rs.getBundledInput("right"), colors.gray))
lightGraycheck =(colors.test (rs.getBundledInput("right"), colors.lightGray))
cyancheck =(colors.test (rs.getBundledInput("right"), colors.cyan))
purplecheck =(colors.test (rs.getBundledInput("right"), colors.purple))
bluecheck =(colors.test (rs.getBundledInput("right"), colors.blue))
browncheck =(colors.test (rs.getBundledInput("right"), colors.brown))
greencheck =(colors.test (rs.getBundledInput("right"), colors.green))
redcheck =(colors.test (rs.getBundledInput("right"), colors.red))
blackcheck =(colors.test (rs.getBundledInput("right"), colors.black))
-- end vars
function setOutput(side,col,vif)
  while (vif) == true do
   rs.setBundledOutput(side,col)
	print (vif)
   sleep(1)
  end --should have put this here
  while (vif) == false do
   rs.setBundledOutput(side,colors.white)
	print (vif)
   sleep(1)
  end --should have put this here
end
setOutput("left",colors.orange,orangecheck)
setOutput("left",colors.magenta,magentacheck)
setOutput("left",colors.lightBlue,lightBluecheck)
setOutput("left",colors.yellow,yellowcheck)
setOutput("left",colors.lime,limecheck)
setOutput("left",colors.pink,pinkcheck)
setOutput("left",colors.gray,graycheck)
setOutput("left",colors.lightGray,lightGraycheck)
setOutput("left",colors.cyan,cyancheck)
setOutput("left",colors.purple,purplecheck)
setOutput("left",colors.blue,bluecheck)
setOutput("left",colors.brown,browncheck)
setOutput("left",colors.green,greencheck )
setOutput("left",colors.red,redcheck)
setOutput("left",colors.black,blackcheck)
end --was not needed here
end --was not needed here
Edit: I also noticed that since I have a "sleep" command in my function, each check should take at least 1 second, but it is processing instantly. not sure if this is valuable bug-squashing info, but thought it was worth notice.
Edit 2: found out that the end commands I had were in the wrong place, so it was skipping my function altogether. Now I have it stuck on an endless loop checking for the Orange input! GAHHHH!!! I can't believe how hard this is! how can you guys stand doing this all day????
Edited on 21 July 2012 - 05:34 PM
OmegaVest #4
Posted 21 July 2012 - 08:39 PM
The only problem I see is that you are trying to check if a variable is changing without it actually ever changing. The top variables are set, period. Unless you make them into functions that return what they are presently set to instantiate at.
Lyqyd #5
Posted 21 July 2012 - 09:23 PM
Is this what you're trying to do:


while true do
    os.pullEvent("redstone")
    redstone.setBundledOutput("left", redstone.getBundledInput("right"))
end
Cranium #6
Posted 21 July 2012 - 10:00 PM
Unless you make them into functions that return what they are presently set to instantiate at.
So how would I go about doing that?
Is this what you're trying to do:


while true do
	os.pullEvent("redstone")
	redstone.setBundledOutput("left", redstone.getBundledInput("right"))
end
I have no idea what that actually does… I can see the os.pullEvent, but where would I jam that into my code?
Lyqyd #7
Posted 21 July 2012 - 10:02 PM
Unless you make them into functions that return what they are presently set to instantiate at.
So how would I go about doing that?
Is this what you're trying to do:


while true do
	os.pullEvent("redstone")
	redstone.setBundledOutput("left", redstone.getBundledInput("right"))
end
I have no idea what that actually does… I can see the os.pullEvent, but where would I jam that into my code?

That is the code. Any time the state of any redstone attached to the computer changes (like any of the inputs on your bundled wires), it sets the output of the left side to match the input on the right side, then waits for another change.
Cranium #8
Posted 21 July 2012 - 10:44 PM
Wait, so you're telling me that all this time, I have been trying to hash out this huge long code, when I only needed 4 lines????
EDIT: Just tested it. I hate you for showing me up….but LOVE YOU FOR MAKING THIS WORK!!!!!!!!
Edited on 21 July 2012 - 08:53 PM