Jump to content




button controlled turtle mining

turtle networking wireless

23 replies to this topic

#21 Robert1707

  • Members
  • 15 posts

Posted 12 July 2015 - 05:45 PM

Hi. Sorry to bother again but I need a bit more help. I have added to the turtle code a section that checks if the chests are full and if so sends a signal to the controller computer. The code I believe is working fine except that I get an error: rednet :47: vm error: java.lang.ArrayIndexOutOfBoundsException

This is the code I am using for the checks

function isCoal()
    if turtle.suck(1) == false then
        rednet.send(25, "cFalse")
        isCoal()
    else
        turtle.drop()
        rednet.send(25, "cTrue")
    end
end

I use a similar code to check the torches chest. The idea behind calling the function again is that the turtle will keep checking the chest until the chest gets restocked. This prevents the turtle from continuing the mining until it has the required items to do so. I think that java is giving this error because it thinks that the turtle is caught in an infinite loop.

Could you suggest a course of action or a fix for this.

Thanks

#22 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 July 2015 - 10:59 PM

View PostRobert1707, on 12 July 2015 - 05:45 PM, said:

I think that java is giving this error because it thinks that the turtle is caught in an infinite loop.

Close. Actually, it's giving you this error because you have more than 256 function calls before any of them end.

TL;DR: Making a function call itself makes this error occur. Instead, use a loop.
local function isCoal()
  while not turtle.suck(1) do
    rednet.send( 25, "cFalse" )
    sleep(0)
  end
  turtle.drop()
  rednet.send( 25, "cTrue" )
end

I believe this will do what you want, while not causing a stack overflow nor a too long without yielding error.

#23 Robert1707

  • Members
  • 15 posts

Posted 13 July 2015 - 11:03 AM

Okay thanks. I'll implement it now

#24 Robert1707

  • Members
  • 15 posts

Posted 18 July 2015 - 07:04 PM

For anyone interested I have finished my code and posted it. Check it out with the link below:

http://www.computerc...wireless-miner/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users