202 posts
Posted 29 January 2014 - 10:15 PM
So I want to add the ability for my turtle to resume what it was doing when it reboots after reloading chunks. I was just wondering how I could do this the best way. I was thinking about it and I think you could do it by saving stuff to a file and then reading that file one boot. Again, I was just wondering what the best way to do this is.
Help is appreciated.
Thanks! :D/>
286 posts
Location
United States
Posted 29 January 2014 - 10:32 PM
There are several discussions here and there about this. If your turtle has GPS it is a bit easier.
You have to save status in a file after each status change. There was an idea on the board (sorry, I don't remember from whom) which used changes in fuel level to determine if the turtle had completed its last forward, back, up or down move (kind of brilliant, actually). At each startup, you read in the status and compare current fuel with what the status file says it should be (that way, you know if the turtle completed the last move). You may want to store things like what the move back to the starting location will be at this point, etc.
Your big problem will be NSEW orientation. For that the GPS may come in handy. On boot up, if the status file exists, then the turtle knows it went through a restart. It then can make a series of moves and checks to determine where it is and whether digging/placing blocks completed before it resumes.
There are probably a few good turtle programs that already do this – tear em apart and see how they handle it.
I have been giving this some though, because I would like to do the same with some of my turtle programs. Just haven't got around to it yet.
7083 posts
Location
Tasmania (AU)
Posted 30 January 2014 - 01:07 AM
The status file is optional, depending on what you're doing. I've got a turtle wandering my base crafting stuff, one harvesting a field, and a few chopping trees (when said trees don't grow over them, deleting them…). All can continue working after a server reboot and none of them write to any files.
Basically, each has a chest it can drop spare/unidentified stuff off into (rigged to automatically pipe its contents off into my barrel system), so when they boot they simply go over to that and offload before starting their tasks from scratch. There's a slight reduction in efficiency, but that only occurs when the server reboots (or when I manually reboot them eg as part of a script update), and the trade off is that I'm not wasting server time with constant file I/O requests.
Their systems rely on GPS to get an initial reading on their locations, but depending on your setup you may not need even that. If your turtle should only need to function in a small area, then you wall it off - on boot, it can follow the walls until it knows its location in the workspace.
Exactly how feasible these methods are depends on how repetitive your scripts are. If you want your turtle to dig a mine shaft a thousand blocks long, then having it start that process over from scratch once it's gone halfway would be strongly undesirable.