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

Possible to write a program/API that launches a program in a resumable manner?

Started by lost_RD, 21 January 2013 - 12:50 PM
lost_RD #1
Posted 21 January 2013 - 01:50 PM
Hey all,

I work in a computing environment with volatile power stability and Minecraft closes often which makes programs such as quarries a PITA as I'm forced to manually reset them which removes the convenient nature of quarrying - I may as well do it myself if it's not automated properly.

My question is, is it possible for a program or API or whatever to be written that saves the state of a program at each step such that the program can be resumed when a computer/turtle is relaunched?

The way I see this working is perhaps by running everything through an API and running a resume program on startup that checks for a program snapshot and resumes it if possible. The API would record the current line/column that the program is at and all variables at every step and save them to file.

This sounds difficult to achieve and probably resource intensive but I lack the knowledge to decide if it is indeed possible so it has come to pass that I ask a pro.

Enlighten me?
Lyqyd #2
Posted 21 January 2013 - 02:12 PM
You'd have to write a program to specifically do this; it's highly unlikely that one would be able to write a wrapper program/API that could resume other programs from where they left off. Alternatively, wait until the mod developers get persistence figured out and the issue will go away magically on it's own, as long as the world is saved properly.
ChunLing #3
Posted 21 January 2013 - 03:20 PM
You can serialize/save a table with all your critical data periodically, and then reload that table when the program starts. Then you just restart it on a reload by having it as the startup (or shell.running it from the startup, if you want to be able to run other programs on that machine which would need to be the startup when they were in action).

Example code lines:
local hndl = fs.open("pdatfl","r")
if hndl then pdat = textutils.unserialize(hndl.readAll()) hndl.close() end
-- other setup stuff
while true do
-- control stuff
-- gather all the data you need
-- update the table
hndl = fs.open("pdatfl","w") hndl.write(textutils.serialize(pdat)) hndl.close()
end