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

Loop error?

Started by jacob070, 06 January 2013 - 06:08 AM
jacob070 #1
Posted 06 January 2013 - 07:08 AM
I need help with this program, i getting this error:

bios:140: vm error: java.lang.ArrayIndexOutOfBoundsException: 256

program check:

Spoilerturtle.select(1)
if turtle.compare() == false then
turtle.select(2)
if turtle.compare() == false then
turtle.select(3)
if turtle.compare() == false then
turtle.select(4)
if turtle.compare() == false then
turtle.select(5)
if turtle.compare() == false then
turtle.select(6)
if turtle.compare() == false then
turtle.dig()
shell.run("turn")

end
else
shell.run("turn")

end
else
shell.run("turn")

end
else

shell.run("turn")

end
else
shell.run("turn")

end
else
shell.run("turn")
end

program turn:

Spoilerif i==4 then
turtle.digDown()
turtle.down()
i = 1
shell.run("check")
else
i = i+1
turtle.turnRight()
shell.run("check")
end
theoriginalbit #2
Posted 06 January 2013 - 07:52 AM
Is there any reason you are using separate files and shell.run? Try moving them into the same file and using functions instead of shell.run


function turn()
  -- do stuff
end

function check()
  -- do stuff
  turn()
end

check()
jacob070 #3
Posted 06 January 2013 - 08:48 AM
Thank you, that helps alot but still the same error….before it was for 4 moves or so,with functions it is for 30 moves.
I need program that dig down to bedrock and mine only ores, so i compare 6 slots with materials i dont want….
farigiss #4
Posted 06 January 2013 - 08:52 AM
Paste your code in code tags.

So formatting like indentation gets preserved. That thing in your original post is nearly impossible to read.
ChunLing #5
Posted 06 January 2013 - 10:45 AM
You're calling turn from check and check from turn. That will overflow the stack in short order if nothing stops one from calling another instance of the other at some point.