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

Computer Craft tunneler problem

Started by popcom, 18 March 2013 - 03:29 PM
popcom #1
Posted 18 March 2013 - 04:29 PM
hello im popcom im trying to work with computer craft right now to use the massive mining machine thing that this guy built i have added both api and program and they seem now to work i dont know what i might be doing wrong or whats up but i keep getting problems

here is the code im writing in the computers floppy disk

os.loadAPI("bc")
os.unloadAPI("bc")

function run()
bc.Add("white")
bc.Pulse("blue,0.2")
os.sleep(2)
bc.Sub("white")
bc.Pulse("blue,0.2")
os.sleep(1)
bc.Pulse("blue,0.2")
os.sleep(1)
bc.Pulse("blue,0.2")
os.sleep(1)
bc.Pulse("blue,0.2")
bc.Pulse("red,0.2")
bc.Pulse("green,0.2")
os.sleep(3)

while 1 == 1 do
if rs.getInput("right") then
run()
else
os.sleep(10)
end





after typing all this in myself onto a disk and typing bore it says :4: call nil value………
Lyqyd #2
Posted 18 March 2013 - 05:04 PM
Split into new topic.
SadKingBilly #3
Posted 18 March 2013 - 05:23 PM
You forgot to end your function definition for run(). You need to add an "end" to the end of the definition, after the "os.sleep(3)" line. Same thing is wrong with the next block of code. You open a while loop and an if-else block, but you only close one of them. Add another end after the last line. You should also post your code for your bc API, because I think you are specifying your arguments incorrectly. Anyway, here's the fixed code:

function run()
   bc.Add("white")
   bc.Pulse("blue,0.2")
   os.sleep(2)
   bc.Sub("white")
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   bc.Pulse("red,0.2")
   bc.Pulse("green,0.2")
   os.sleep(3)
end
while true do
   if rs.getInput("right") then
	  run()
   else
	  os.sleep(10)
   end
end
remiX #4
Posted 18 March 2013 - 05:49 PM
And change
os.loadAPI("bc")
os.unloadAPI("bc")
to
os.unloadAPI("bc")
os.loadAPI("bc")

First unload it, then load it.
Loading and then unloading means you won't be able to use it's functions.
popcom #5
Posted 18 March 2013 - 07:25 PM
"back"
function Add(color1)
c = rs.getBundledOutput(side)
if color1 == "white" then
c = colors.combine(c,colors.white)
elseif color1 == "orange" then
c = colors.combine(c,colors.orange)
elseif color1 == "magenta" then
c = colors.combine(c,colors.magenta)
elseif color1 == "lightblue" then
c = colors.combine(c,colors.lightBlue)
elseif color1 == "yellow" then
c = colors.combine(c,colors.yellow)
elseif color1 == "lime" then
c = colors.combine(c,colors.lime)
elseif color1 == "pink" then
c = colors.combine(c,colors.pink)
elseif color1 == "gray" then
c = colors.combine(c,colors.gray)
elseif color1 == "lightgray" then
c = colors.combine(c,colors.lightGray)
elseif color1 == "cyan" then
c = colors.combine(c,colors.cyan)
elseif color1 == "purple" then
c = colors.combine(c,colors.purple)
elseif color1 == "blue" then
c = colors.combine(c,colors.blue)
elseif color1 == "brown" then
c = colors.combine(c,colors.brown)
elseif color1 == "green" then
c = colors.combine(c,colors.green)
elseif color1 == "red" then
c = colors.combine(c,colors.red)
elseif color1 == "black" then
c = colors.combine(c,colors.black)
end

rs.setBundledOutput(side,c)
end
function Sub(color1)
c = rs.getBundledOutput(side)
if color1 == "white" then
c = colors.subtract(c,colors.white)
elseif color1 == "orange" then
c = colors.subtract(c,colors.orange)
elseif color1 == "magenta" then
c = colors.subtract(c,colors.magenta)
elseif color1 == "lightblue" then
c = colors.subtract(c,colors.lightBlue)
elseif color1 == "yellow" then
c = colors.subtract(c,colors.yellow)
elseif color1 == "lime" then
c = colors.subtract(c,colors.lime)
elseif color1 == "pink" then
c = colors.subtract(c,colors.pink)
elseif color1 == "gray" then
c = colors.subtract(c,colors.gray)
elseif color1 == "lightgray" then
c = colors.subtract(c,colors.lightGray)
elseif color1 == "cyan" then
c = colors.subtract(c,colors.cyan)
elseif color1 == "purple" then
c = colors.subtract(c,colors.purple)
elseif color1 == "blue" then
c = colors.subtract(c,colors.blue)
elseif color1 == "brown" then
c = colors.subtract(c,colors.brown)
elseif color1 == "green" then
c = colors.subtract(c,colors.green)
elseif color1 == "red" then
c = colors.subtract(c,colors.red)
elseif color1 == "black" then
c = colors.subtract(c,colors.black)
end
if color1 == "all" then
rs.setBundledOutput(side,0)
else
rs.setBundledOutput(side,c)
end
end
function pulse(color,time)
if time == "" or time == 0 then time = 0.1 end
Add(color)
os.sleep(time)
Sub(color)
end
popcom #6
Posted 19 March 2013 - 03:13 AM
And change
os.loadAPI("bc")
os.unloadAPI("bc")
to
os.unloadAPI("bc")
os.loadAPI("bc")

First unload it, then load it.
Loading and then unloading means you won't be able to use it's functions.


yea well even trying it your way seems to give me an error "bc is already loading"
current problem is
wires are not activating

currently just testing one or 2 lines of the code to see if it will activate the RS current and make the wires activate with this

bc.Add("white")
bc.Pulse("red,0.2")
end

nothing seems to happen at all.


(i made a redstone circuit which currently does all the timings perfectly)
if i cannot get the computer thing working i might just stick with this circuit
remiX #7
Posted 19 March 2013 - 03:26 AM
API
local c

function resetAll( side )
	rs.setBundledOutput( side, 0 )
end

function subract( side, color )
	c = rs.getBundledOutput(side)
	if type( color ) == 'number' or ( type( color ) == 'string' and colors[color] ) and rs.testBundledInput( side, color ) then
		c = colors.subract( c, color )
	end
	rs.setBundledOutput( side, c )
end

function add( side, color )
	c = rs.getBundledOutput(side)
	if type( color ) == 'number' or ( type( color ) == 'string' and colors[color] ) and not rs.testBundledInput( side, color ) then
		c = colors.combine( c, color )
	end
	rs.setBundledOutput( side, c )
end

Program
os.loadAPI( 'bc' )

-- You can use colors.white or 'white' to add it, same with subtracting
bc.add( 'right', colors.white )
bc.add( 'right', 'red' )

bc.subract( 'right', colors.red )

bc.resetAll( 'right' )

Haven't tested it so not sure if it will work :P/>/>
theoriginalbit #8
Posted 19 March 2013 - 03:30 AM
Haven't tested it so not sure if it will work :P/>/>
Won't work for things like "red" you made 1 mistake and did

if type( color ) == 'number' or ( type( color ) == 'string' and colors[color] ) and not rs.testBundledInput( side, color ) then
  c = colors.combine( c, color )
end
you should have done

if type( color ) == 'number' and not rs.testBundledInput( side, color ) then
  c = colors.combine( c, color )
elseif type( color ) == 'string' and colors[color] and not rs.testBundledInput( side, colors[color] ) then
  c = colors.combine( c, colors[color] )
end
and the same in subtract too.
remiX #9
Posted 19 March 2013 - 04:23 AM
But my if statement should work I'm sure?

Or maybe it should be this:

if ( type( color ) == 'number' or ( type( color ) == 'string' and colors[color] ) ) and rs.testBundledInput( side, color ) then
popcom #10
Posted 19 March 2013 - 04:31 AM
okay now im really confused……….
and i dont wanna test it because that requires to make more stuff i dont know about. i just wanna get the codes i have working

oh and i dident write the bc code i just got it from the guys video so….
popcom #11
Posted 22 March 2013 - 07:57 AM
guess not
theoriginalbit #12
Posted 22 March 2013 - 07:59 AM
okay now im really confused……….
and i dont wanna test it because that requires to make more stuff i dont know about. i just wanna get the codes i have working

oh and i dident write the bc code i just got it from the guys video so….

guess not
What is wrong with the current code? also what IS the current code?!
popcom #13
Posted 23 March 2013 - 05:22 AM
okay first api then program


api


side = "back"
function Add(color1)
  c = rs.getBundledOutput(side)
	if color1 == "white" then
	  c = colors.combine(c,colors.white)
	elseif color1 == "orange" then
	  c = colors.combine(c,colors.orange)
	elseif color1 == "magenta" then
	  c = colors.combine(c,colors.magenta)
	elseif color1 == "lightblue" then
	  c = colors.combine(c,colors.lightBlue)
	elseif color1 == "yellow" then
	  c = colors.combine(c,colors.yellow)
	elseif color1 == "lime" then
	  c = colors.combine(c,colors.lime)
	elseif color1 == "pink" then
	  c = colors.combine(c,colors.pink)
	elseif color1 == "gray" then
	  c = colors.combine(c,colors.gray)
	elseif color1 == "lightgray" then
	  c = colors.combine(c,colors.lightGray)
	elseif color1 == "cyan" then
	  c = colors.combine(c,colors.cyan)
	elseif color1 == "purple" then
	  c = colors.combine(c,colors.purple)
	elseif color1 == "blue" then
	  c = colors.combine(c,colors.blue)
	elseif color1 == "brown" then
	  c = colors.combine(c,colors.brown)
	elseif color1 == "green" then
	  c = colors.combine(c,colors.green)
	elseif color1 == "red" then
	  c = colors.combine(c,colors.red)
	elseif color1 == "black" then
	  c = colors.combine(c,colors.black)
	end

  rs.setBundledOutput(side,c)
end
function Sub(color1)
  c = rs.getBundledOutput(side)
	if color1 == "white" then
	  c = colors.subtract(c,colors.white)
	elseif color1 == "orange" then
	  c = colors.subtract(c,colors.orange)
	elseif color1 == "magenta" then
	  c = colors.subtract(c,colors.magenta)
	elseif color1 == "lightblue" then
	  c = colors.subtract(c,colors.lightBlue)
	elseif color1 == "yellow" then
	  c = colors.subtract(c,colors.yellow)
	elseif color1 == "lime" then
	  c = colors.subtract(c,colors.lime)
	elseif color1 == "pink" then
	  c = colors.subtract(c,colors.pink)
	elseif color1 == "gray" then
	  c = colors.subtract(c,colors.gray)
	elseif color1 == "lightgray" then
	  c = colors.subtract(c,colors.lightGray)
	elseif color1 == "cyan" then
	  c = colors.subtract(c,colors.cyan)
	elseif color1 == "purple" then
	  c = colors.subtract(c,colors.purple)
	elseif color1 == "blue" then
	  c = colors.subtract(c,colors.blue)
	elseif color1 == "brown" then
	  c = colors.subtract(c,colors.brown)
	elseif color1 == "green" then
	  c = colors.subtract(c,colors.green)
	elseif color1 == "red" then
	  c = colors.subtract(c,colors.red)
	elseif color1 == "black" then
	  c = colors.subtract(c,colors.black)	
	end
  if color1 == "all" then
	rs.setBundledOutput(side,0)
  else
	rs.setBundledOutput(side,c)
  end
end
function pulse(color,time)
if time == "" or time == 0 then time = 0.1 end
Add(color)
os.sleep(time)
Sub(color)
end


program

function run()
   bc.Add("white")
   bc.Pulse("blue,0.2")
   os.sleep(2)
   bc.Sub("white")
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   os.sleep(1)
   bc.Pulse("blue,0.2")
   bc.Pulse("red,0.2")
   bc.Pulse("green,0.2")
   os.sleep(3)
end
while true do
   if rs.getInput("right") then
		  run()
   else
		  os.sleep(10)
   end
end
popcom #14
Posted 23 March 2013 - 05:23 AM
I did not understand what they were talking about above so I hadent changed the api or program from what thecorykid suggested something Is very wrong with the forum shift enter does not work and well its being quite annoying anyways I tried running the script's and it just says no such program ….. for both api and program don't know what im doing wrong now when I run bore it says file not found………..
popcom #15
Posted 23 March 2013 - 12:07 PM
I cant figure it out I dono what im doing wrong
immibis #16
Posted 23 March 2013 - 01:42 PM
Your quotes are in the wrong place.

bc.Pulse("blue,0.2") -- This pulses the colour "blue,0.2" and you haven't specified the time. In other words, it's wrong.
bc.Pulse("blue",0.2) -- This pulses the colour "blue" for 0.2 seconds. In other words, it's right.
popcom #17
Posted 24 March 2013 - 07:21 AM
okay now I got It working. but I used the pastebin to get it and it only allows me to put it on the computer itself but when I remove the computer I lose it :S where can I put the files to have them for good? also is there a way I can make the program quit by pressing a button such as space, as it is now after typing bore I cannot stop the program and that is not helpful when wanting to edit the program…… or not have to smash and redownload the program and api over again
Lyqyd #18
Posted 24 March 2013 - 09:12 PM
If you label your computers (at the command line, `label set ComputerNameHere`), they will not lose their programs when you break them.