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

[Question][Lua]Is there any way to make program reload

Started by exploder, 14 September 2012 - 04:33 PM
exploder #1
Posted 14 September 2012 - 06:33 PM
Hello everybody.

I am playing on MultiPlayer server (which isn't mine), and when you leave the server (when nobody is around your house), then everything stops.

And I have Mining Turtle Program who stops alwell, so I can't leave the server till it's finished.

And I wanted to ask you, is there any way, to make program reload (or continue) it's work, after you have been reconnected.

Here's the code, if that helps.

SpoilerHere is the link to PasteBin:
http://pastebin.com/hW8URLwu

Thank you for reading.
-Exploder
Cranium #2
Posted 14 September 2012 - 06:41 PM
So are you wanting it to resume from where it left off? If so, then you will have to write into it a savestate file, where it knows where it was last, and resume from there. This is a litle bit of a pain to do, but can be done.
exploder #3
Posted 14 September 2012 - 06:46 PM
So are you wanting it to resume from where it left off? If so, then you will have to write into it a savestate file, where it knows where it was last, and resume from there. This is a litle bit of a pain to do, but can be done.

Thank you for replaying, and helping.

Yes, I want the program to continue where it left off last time.
Is there a chance, that you would show me a little example, how I should create one like that, or it's a bit too difficult to make?
Anyway's thanks for helping.
Cranium #4
Posted 14 September 2012 - 07:15 PM

local turtleX = 0
local turtleY = 0
local turtleZ = 0

local function savePos(x,y,z)
local file = fs.open("position","w")
file.write(x..","..y..","..z)
file.close()
end

local function tForward()
if not turtle.forward() then
turtle.dig()
turtle.forward()
end
turtleX = turtleX + 1
savePos(turtleX,turtleY,turtleZ)
end

Just a quick write up, not tested though. This is just for moving forward. you would have to adjust accordingly for Y and Z coordinates.
exploder #5
Posted 15 September 2012 - 09:09 PM

local turtleX = 0
local turtleY = 0
local turtleZ = 0

local function savePos(x,y,z)
local file = fs.open("position","w")
file.write(x..","..y..","..z)
file.close()
end

local function tForward()
if not turtle.forward() then
turtle.dig()
turtle.forward()
end
turtleX = turtleX + 1
savePos(turtleX,turtleY,turtleZ)
end

Just a quick write up, not tested though. This is just for moving forward. you would have to adjust accordingly for Y and Z coordinates.

Thank you, I will definitely try that out.