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

Workaround for lack of persistance?

Started by The Lone Wolfling, 26 February 2015 - 12:32 PM
The Lone Wolfling #1
Posted 26 February 2015 - 01:32 PM
Is there a current workaround for the lack of persistance for turtles? In particular, making sure files are saved in sync with position, and checking if movement did / didn't work?

If not, is there an addon that adds something to check XYZ / direction for turtles? I've seen things that do one or the other, but not both. And having to move forward / back just to check facing is… suboptimal. GPS isn't something I like, due to the limited range. I'd increase the range, but there's no way to increase the range of GPS without increasing the range of wireless modems, that I know of at least.
Bomb Bloke #2
Posted 26 February 2015 - 01:48 PM
Short of hammering your servers HDD by writing and rewriting files saying "I just performed this action and am now at X/Y/Z" for every movement you make (a process I don't much recommend), there's GPS, and there's making the turtle bump into walls until it figures out where it is (eg, build a play-pen of a certain shape for your turtle to operate in, and on boot it should be able to figure out its exactly location by "feeling" the layout of the walls).

GPS range is indeed equal to modem range - modem messages carry a tag indicating the distance they travelled, and the GPS API is merely a chunk of code that calls for messages from a number of systems that already know their location, examines the distance tags, and figures out where the asking system must be based on that data.

Modem range gets higher as you approach world-height, and only the range of the highest system matters when determining if two systems can communicate. Thus a GPS cluster up the top of your map can cover a bit over a few hundred blocks (bearing in mind that I'm talking about the radius of a sphere, not a plain circle).

In the case of mining turtles - ones dedicated to gathering materials, as opposed to digging holes of certain shapes - I don't think it should much matter if they know where they are or not. Give them an ender chest to carry, attach a chunk loader peripheral, set them loose in the world (er, or in a mining / MystCraft age) and forget about them.
The Lone Wolfling #3
Posted 26 February 2015 - 03:51 PM
Short of hammering your servers HDD by writing and rewriting files saying "I just performed this action and am now at X/Y/Z" for every movement you make (a process I don't much recommend),
Not really true. Saving coordinates to a file doesn't work, because files aren't saved in sync with the rest of the world, as I said in my first post. If there was a way to store data in the tile entity, this could work, as tile entities are saved at the same time as the rest of the world. But I don't know of a way to do this.

GPS range is indeed equal to modem range
So there isn't a way, then. So is there an addon that allows you to get XYZ/facing coordinates without being in range? Or an addon that decouples GPS range from modem range?


In the case of mining turtles - ones dedicated to gathering materials, as opposed to digging holes of certain shapes - I don't think it should much matter if they know where they are or not. Give them an ender chest to carry, attach a chunk loader peripheral, set them loose in the world (er, or in a mining / MystCraft age) and forget about them.
First off, it's SSP, hence the question. So chunkloaders don't work. Second off, I'm using just CC - no chunk loaders, no ender chests. If either of those were in CC, it might make a difference.

Secondly, this is not a mining turtle. I'm looking for something that should be easy - and would be easy if CC were persistant. However, it still isn't. So I'm looking for a workaround.

(I got fed up enough with CC that I'm writing a persistant forth intrepreter, because I found it easier than trying to deal with the lack of persistance in CC. (And that's saying something…) And for most things it seems to work. But even that doesn't work for turtles / external observables, because of the aforementioned state inconsistancies with saving to files. And even without the state inconsistancies, I've found no way to detect if a turn was actually completed or not, among other things.)
MKlegoman357 #4
Posted 26 February 2015 - 04:21 PM
What Bomb Bloke meant is that after every move, turn, dig, etc.. operation you'd save the coordinates and other data into a file immediately after it finished. There is file.flush so you don't have to close and reopen the file to save the data.
The Lone Wolfling #5
Posted 26 February 2015 - 04:42 PM
What Bomb Bloke meant is that after every move, turn, dig, etc.. operation you'd save the coordinates and other data into a file immediately after it finished. There is file.flush so you don't have to close and reopen the file to save the data.
I know what Bomb Bloke meant. But this does not work.

Minecraft only saves the world every so often. As a result, what can happen is that you write the file, the file saves to disk, then MC exits unexpectedly and doesn't save the block data. As a result, your data saved to disk is out of sync with the world - you have an older version of the block data but a newer version of the file data.

And even if it did work as expected, there is still a race condition here if it exits between doing the operation and updating the file. I've had this happen with quarry turtles before.
Edited on 26 February 2015 - 03:42 PM
Lyqyd #6
Posted 26 February 2015 - 04:49 PM
Yes, it actually does work. Using fuel levels in conjunction with the last known coordinates and the last known instructed move, it is entirely possible to be accurate with the saving-location-to-disk method. This is the concept that LAMA is based on.

Also, it would almost certainly be easier to create a peripheral mod to give turtles their coordinates and facing direction than to re-create their functionality in another mod (though, amusingly enough, that's roughly what Sangar, the author of the post linked above, did with OpenComputers). And of course, if persistence is the biggest priority for you, you may want to look into whether OpenComputers is a better fit for you, if neither of the options above work for you.
The Lone Wolfling #7
Posted 26 February 2015 - 08:38 PM
Yes, it actually does work. Using fuel levels in conjunction with the last known coordinates and the last known instructed move, it is entirely possible to be accurate with the saving-location-to-disk method. This is the concept that LAMA is based on.
How does this work with turns? Fuel doesn't go down when turning…

Also, there's a comment to the effect of LAMA not working with CC 1.63. I'll have to check if it works with 1.73, but I'm not optimistic.

Not to mention this still doesn't work with axillary state. Unless I'm missing something?

LAMA would be great if it works, and if it allows saving of axillary state that remains synced with world state.

Also, it would almost certainly be easier to create a peripheral mod to give turtles their coordinates and facing direction than to re-create their functionality in another mod (though, amusingly enough, that's roughly what Sangar, the author of the post linked above, did with OpenComputers). And of course, if persistence is the biggest priority for you, you may want to look into whether OpenComputers is a better fit for you, if neither of the options above work for you.
OpenComputers would be a better fit for me, if it were just CC + persistence. Unfortunately, OC has made a bunch of "improvements" that I don't like. Now, if someone made an OC lite that aimed to be a faithful replacement of CC, that would be great. (I.e. recipes the same, functionality the same (or equivalent).) But unless I'm missing something there's no way to do that currently.

I'll think about making a peripheral mod, but I'd rather not make mods just work work around bugs in other mods if I don't have to.
Lyqyd #8
Posted 26 February 2015 - 08:53 PM
Turns don't comsume fuel, but also cannot fail, assuming the function is called before the turtle is unloaded. I have observed them completing turns upon reloading. LAMA cannot keep track of the state of the running program, only the turtle's position and heading, so far as I am aware. If the 1.6 updates broke it, that's unfortunate, as it was likely taking advantage of the old turtle.x / turtle.native.x structure of the API, which no longer exists.

Did I misinterpret your comment about making a Forth interpreter? I had thought you meant that you were creating a turtles-esque mod using a language that would be easier to serialize state and this achieve persistence. If you instead meant that you were creating a Lua program that is a Forth interpreter, that's potentially a viable strategy for program persistence, but would still need something like LAMA to be able to know if a turtle movement succeeded or failed if ot occurred across an unload/reload.

And I agree about OC, just figured I'd throw it out there in case you weren't already aware.
The Lone Wolfling #9
Posted 26 February 2015 - 10:29 PM
Turns don't comsume fuel, but also cannot fail, assuming the function is called before the turtle is unloaded. I have observed them completing turns upon reloading. LAMA cannot keep track of the state of the running program, only the turtle's position and heading, so far as I am aware. If the 1.6 updates broke it, that's unfortunate, as it was likely taking advantage of the old turtle.x / turtle.native.x structure of the API, which no longer exists.
Race conditions, so many race conditions…

Did I misinterpret your comment about making a Forth interpreter?
Yes you did. I'm making a Lua Forth interpreter, hence the requested workaround.