Turtles stop working even with Chunk Loaders

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

JMC17

New Member
Jul 29, 2019
3
0
0
http://pastebin.com/j48M7FN2
Code:
--8 rows
--23 blocks large
--42 blocks long
END=0
ib=0
 
function DetectGlass()
turtle.select(16)
if turtle.compare() then
error("Perimeter Detected")
end -- if not
end -- Detect Glass
 
function RowFront()
i=1
while i<42 do
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end -- Force Forward END
i=i+1
end -- while END
turtle.turnRight()
DetectGlass()
turtle.dig()
turtle.suckUp()
turtle.suckDown()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end -- while END
turtle.turnRight()
end -- Row END
 
function RowBack()
ia=1
while ia<42 do
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end -- Force Forward END
ia=ia+1
end -- while END
turtle.turnLeft()
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end --while not
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end --while not
print(ib)
turtle.turnLeft()
end -- Row END
 
repeat
 
 
--Workflow
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end -- while not end
ib=0
while ib<8 do
ib=ib+1
RowFront()
RowBack()
end --while END
 
turtle.turnLeft()
turtle.turnLeft()
DetectGlass()
turtle.dig()
while not turtle.forward() do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
ic=1
while ic<25 do
ic=ic+1
DetectGlass()
while not turtle.forward() do
turtle.dig()
turtle.forward()
end --while not END
end --while END
turtle.turnRight()
print("Unloading")
id=1
while id<15 do
id=id+1
turtle.select(id)
turtle.dropDown()
end
turtle.select(16)
until END==1

Alright here's more details..
The above is a sugar cane farming script, it harvests each rows then comes back to its start and drop off the canes.
It also keeps a glass cube to compare with that it is digging to prevent it from running away, since it has glass walls all around.

The farm itself is well covered by a chunk loader (max range chunk loader) and I even installed another one just for that farm in case something went wrong with the first one.
I also made sure nothing can sneak in my farm, no passives nor hostiles.
My turtles never run into anything else than sugar canes and empty blocks.

The problem is, it works great when i'm online, even if i'm very far away but the moment I log off, even though the server is still on, my turtles goes crazy and either corrupts its programming by changing its patterns or gets stuck in a loop and digs forever forward. Which is why I implemented the perimeter detection..

Now I know my script is just fine! It worked all day long (played for more than 12 hours without a problem) but the moment I logged off to go to sleep they stopped working correctly. (Running into walls; digging where it shouldn't)

There might be solutions when it comes to my script, like implementing a GPS system but at that point i'd rather just stay logged on instead..
I'll listen to all suggestions but I'd prefer the focus to not be on how to get around the problem but on what is causing it.

I was thinking, the excavate script works great, even when offline. So perhaps there's something i'm using in my script that causes that to happen. Anyhow, i'm really puzzled by this problem and hope I won't be the only one.
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
while not turtle.forward() do
turtle.dig()
turtle.forward()
turtle.suckUp()
turtle.suckDown()
end -- Force Forward END
"while not turtle.forward() do" makes the turtle attempt to move forward, same as just "turtle.forward()" would. With this in mind you can probably see the source of your errors.

To elaborate, if it can't move forward, then it digs and moves forward. Then it performs the check to see if it can move forward again, which involves attempting to move forward again... So if that also fails the turtle will simply dig again, move and then try the move/check again, and so on. This may result in many more moves then you intended, meaning the turtle loses track of where it's up to.

You likely want to use "if not turtle.forward() then" instead of "while not turtle.forward() do".
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
The funny thing is that it mixes both if and while in here.

Usually, when you want to insure it will move forward no matter what:
Code:
while (not turtle.forward()) do
  if (turtle.detect()) then
    turtle.dig()
  else
    turtle.attack()
  end
end
this little thing makes it continuously try to move forward, and dig/attack if it can't.

Also, please do use functions for all the pieces of code that appear more than once, because it makes it really easier to read and to check for errors.

Just like that, I don't see specific error except for those while/if confusion, but there is way too much code that just is not necessary and makes it harder to troubleshoot.
 

vScourge

New Member
Jul 29, 2019
71
0
0
Are you using actual chunk loaders? When it comes to turtles I've only had success with Railcraft World Anchors. The chunk loader turtle upgrade from MiscPeripherals also works, but requires someone to be logged in. World Anchors placed in the turtle's area do not.
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
I've only ever used them with ChickenChunks chunk loaders, which they seem quite happy with.

But in this case, the fact that the turtles keep operating (even if they're not doing what JMC wants them to) indicates that the chunk loaders aren't the problem - his logout times are co-incidental. A turtle in an unloaded chunk stops dead and dumps its RAM, it doesn't start digging non-stop.
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
The problem could come from the fact that the program is on "startup" too.

If the turtle was unloaded eve for a tick, it would restart, but from the wrong place, completely messing the whole place.
 

vScourge

New Member
Jul 29, 2019
71
0
0
The problem could come from the fact that the program is on "startup" too.
If the turtle was unloaded eve for a tick, it would restart, but from the wrong place, completely messing the whole place.

Exactly. If the turtle is not where the program expects it to be on startup, all kinds of bad can happen. You only have a few options there... 1. Make your program fully support state-saving/restore with every single move (ugh), 2. At startup make sure it can go back to a known "home" position no matter where it is (not much easier), or 3. Make sure the chunks it's in never unload.

I believe the ComputerCraft author has said he'd like to add native state saving/loading, but I can see how that might not be a simple feature to add.
 

Bomb Bloke

New Member
Jul 29, 2019
612
0
0
True, but that IS assuming the script runs on startup. Assuming the op's correct in stating the chunk loaders fully cover the farm, the only way the turtle will be unloading is if the server restarts, so that may be worth looking into.