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

strange computing bug code or computercraft?

Started by Explosivecoin, 07 July 2013 - 04:23 PM
Explosivecoin #1
Posted 07 July 2013 - 06:23 PM
error
minecraft 152 mod pack : ftb 152ngt modified computer craft :1.5.3
error : bios : 100 : vm error : java.lang.ArrayIndexOutOfBoundsException: -3
press any key to continue

code of the turtle in question :

rednet.open("right")
while true do
  local id, string ,distance = rednet_message
  if string == "harvest" then
	shell.run("harvest")
  else
  end
end

as the start up and this is the main sugar cane harvesting program :
local function harvest()
  for i = 1,64 do
	turtle.dig()
	turtle.forward()
	turtle.digDown()
  end
  turtle.forward()
  if turtle.getFuelLevel() <= 5000 then
	turtle.select(1)
	turtle.refuel(64)
	turtle.select(1)
  end
end

local function rowswitchRight()
  turtle.turnRight()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
end

local function rowswitchLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.forward()
  turtle.turnLeft()
end

local function switchlaneRight()
  turtle.turnRight()
  turtle.forward()
  turtle.turnRight()
end

local function switchlaneLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
end

local function dropoff()
  turtle.select(16)
  turtle.placeDown()
  for i = 1,15 do
	turtle.select(i)
	turtle.dropDown()
	end
  turtle.select(16)
  turtle.digDown()
  turtle.select(1)
end

--first row

harvest()
rowswitchRight()

--bulk harvest

for i = 1,6 do
  harvest()
  switchlaneLeft()
  harvest()
  rowswitchRight()
  dropoff()
end

--last row
harvest()

--return to start

turtle.turnRight()
for i = 1,20 do
  turtle.forward()
end
turtle.turnRight()
dropoff()

there is a turtle at the other end with a simple shell.run() and this code :

rednet.open("right")
while true do
  if turtle.suckDown then
	print("no more sugar cane")
	rednet.broadcast("harvest")
	print("sent message to sugar farmer")
  end
  sleep(60)
end

im wondering if the error is my code or a computer craft bug

and the server console has this error whenever I place down the turtles:



2013-07-07 17:28:22 [INFO] [STDOUT] ComputerCraft: Error running task.
2013-07-07 17:28:22 [INFO] [STDERR] java.lang.ThreadDeath
2013-07-07 17:28:22 [INFO] [STDERR] at java.lang.Thread.stop(Unknown Source)

2013-07-07 17:28:22 [INFO] [STDERR] at dan200.computer.core.ComputerThread$1
.run(ComputerThread.java:153)
2013-07-07 17:28:22 [INFO] [STDERR] at java.lang.Thread.run(Unknown Source)
Edited by
Lyqyd #2
Posted 08 July 2013 - 08:04 PM
Split into new topic.
GopherAtl #3
Posted 08 July 2013 - 08:08 PM
In the loop at the end, you're not calling turtle.suckDown, just testing if turtle.suckDown exists. You forgot the ()? That shouldn't be causing the error you report, though. On first glance, not seeing what is; generally, the java array out of bounds error means a recursion overflow. Is this all of the code?
CoderPuppy #4
Posted 08 July 2013 - 08:24 PM
The error might be caused by line 3. You're trying to assign three values to one. Try changing it to local id, string ,distance = os.pullEvent("rednet_message") Also you shouldn't use string as a variable name because that's the name of an API.
Explosivecoin #5
Posted 13 July 2013 - 01:26 PM
thanks for the input but I completely rewrote the code to be more efficient at farming the cane and works much better than the code here
electrodude512 #6
Posted 13 July 2013 - 08:22 PM
I've gotten that error before but assumed it was a OpenPeripheral bug with my terminal glasses monitor. Does anyone know exactly which thread is dying? The CC Lua thread I assume or something else? For a while the computer in my base that does just about everything was really screwed up (ctl+R didn't even work!) and then after much removing things and putting them back it decided to work again.