I have a question related to this.
I understand the computer "restarts" every time it's moved. That's fine. I wrote my code around that limitation, but I've run into another problem.
My program basically lets the user give it a direction and a number of blocks to move the frame. The program checks the number, and if it's greater than 1, it writes a file to the disk with the direction and the distance that will still need to be travelled after it moves once, closes the file, and then moves one block in the direction specified.
After moving, the computer "reboots", and the startup program looks for the file, if it's there, it reads in the direction and distance, decrements distance, rewrites the file, and moves again (Assuming distance was greater than zero).
The thing is, this works, but only once. If I type in "drive n 5", it moves north, restarts, moves north again, and then just stops. The computer seems to stop restarting itself. If I right click the computer, it will start up and load the startup file and move again. If I keep right clicking after each move, it will eventually finish out the queued movements, and give me a prompt again. But it requires manual intervention after that second move.
Does anyone have any idea why this is? Is there any way I could work around it?
[EDIT: Just in case it might help, my code follows. I had to type it in by hand, don't know how (If it's even possible) to copy and paste out of a CC computer.
drive program:
local carriage = peripheral.wrap("bottom")
local args = {...}
local dir = -1
local dist = 1
if #args > 0 then
if args[1] == "d" then
dir = 0
elseif args[1] == "u" then
dir = 1
elseif args[1] == "n" then
dir = 2
elseif args[1] == "s" then
dir = 3
elseif args[1] == "w" then
dir = 4
elseif args[1] == "e" then
dir = 5
end
if #args > 1 and tonumber(args[2]) ~= nil then
dist = tonumber(args[2])
end
if dist > 1 then
dist = dist - 1
local h = fs.open("movequeue", "w")
h.writeLine(dir)
h.writeLine(dist)
h.close()
end
if dir ~= -1 then
carriage.move(dir, false, false)
end
end
startup file:
if fs.exists("movequeue") then
local h = fs.open("movequeue", "r")
local dir = tonumber(h.readLine())
local dist = tonumber(h.readLine())
h.close()
local carriage = peripheral.wrap("bottom")
if dir ~= nil and dist > 0 then
dist = dist - 1
h = fs.open("movequeue", "w")
h.writeLine(dir)
h.writeLine(dist)
h.close()
carriage.move(dir, false, false)
end
end