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

Reloading a savegame question

Started by pipa, 15 March 2013 - 05:11 AM
pipa #1
Posted 15 March 2013 - 06:11 AM
Hello,

made a simple script in ssp for my turtle which contains a little file that records every step it does so incase i open/close the game the turtle will find it's way back and restart.

That was my plan, however in theory every time i exit/open the game the coordinates are off by 1 block.
Is there any solution to this, otherwise i will set up a gps.

Example of the code i am using: c[1] = X, c[2]= Y, c[3] = Z, c[4] = (f) direction

while not (c[3] == 2) do
		if turtle.forward() then
					c[3] = c[3] + 1
					local file = fs.open("cord","w")
					file.write(textutils.serialize(c))
					file.close()
		end
end
theoriginalbit #2
Posted 15 March 2013 - 06:13 AM
chances are the reason this is happening is because the turtle has moved as you are closing the game, but the coord has not been written yet. Sadly the only way to fix this is a gps system.
pipa #3
Posted 15 March 2013 - 06:18 AM
Ah well, wish there was something that could hold the savegame open till the loop was at least completed for one step.

Thanks for the help, gps it is then.
Lyqyd #4
Posted 15 March 2013 - 06:20 AM
No, it's not the only way to fix this.

You can try pre-saving your coordinates. Essentially, before each move or turn, you write to disk what your new position will be if it succeeds. If the move succeeds, you're already done. If the move fails, you write your actual coordinates back into your saved location. The idea is that move failures return quite quickly, so you are going to encounter a problem with the coordinates less often than if you save afterwards. For perfect location data, it's best to use GPS or a companion turtle. The companion would follow behind (so its moves are known to succeed. It also uses the pre-write technique, so it can be asked for location data upon startup. If everything is set up correctly, they can only be one or two blocks from each other and it's possible to figure out their relative locations, and thus, the correct position of the main turtle.
pipa #5
Posted 15 March 2013 - 06:26 AM
That is quite a brilliant idea and will definitly try that before i use the gps.

I have used "companion idea" for the misc peripheral interactive sorter, but for a simple cacti farm i will probably use the gps as i plan on adding more turtle powered farms.

Thanks for the idea :)/>