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

Save Info so it can be called after world restart

Started by The_Cat, 26 October 2015 - 04:08 PM
The_Cat #1
Posted 26 October 2015 - 05:08 PM
Hello all,

So I am simply trying to store the position of a turtle (or other info) so I have pos.x pos.y pos.z, when these values change I would like to update these values to a separate file (pref in tables) + pull info from it so after a restart of the world the turtle can resume what it was doing. I have tried using fs and io but i can't seem to get any results that i am looking for.

Thanks,
-The_Cat
Creator #2
Posted 26 October 2015 - 06:19 PM
Use file = fs.open(path,"w") file.write(stuff) to write and file = fs.open(path,"r") stuff = fs.read all() to read. I can't write properly because of phone reasons.

Also use file.close() at the end of each.
KingofGamesYami #3
Posted 26 October 2015 - 07:26 PM
My autosaving table stuff might be helpful in this case.


--#my stuff here
local pos
if fs.exists( ".pos" ) then
  local file = fs.open( ".pos", "r" )
  pos = textutils.unserialize( file.readAll() )
  file.close()
end

pos = makeAutoSaving( pos, ".pos" )

From this point on, any edit to the values in the table 'pos' will be saved to the file at the time of the change.