Posted 30 January 2014 - 02:53 PM
Hello, today i am trying to learn how to read and write info to a text file from my turtle, so i decided to start with something simple, a chunk loading turtle that does a spiral pattern. for the most part i understand the code, but i am having problems writing a changing variable to the file.
I start out with the turtle grabbing value for "y" from a file, which in this case i had set up earlier with the value 32, then it does it's thing with it, moves, adds 32 to it a few times, then it writes it to the file, so that the next time i run the program, it picks up from where it left off on the size of the spiral. Where my problem is, is I want to write the value of "y" to the file, but obviously that gives an error when i just use file.write(y). What is the proper syntax for this?
peripheral.wrap("right")
local tArgs = {...}
local file = fs.open("save", "r")
local y = file.readAll()
file.close()
if tArgs[1] == nil then tArgs[1] = 1 end
function legs()
for i = 1, y do
turtle.forward()
end
turtle.turnLeft()
y = y + 32
end
function whole()
for i = 1, 4 do
legs()
end
file = fs.open("save" , "r")
file.write(y)
file.close()
end
for i = 1, tArgs[1] do
whole()
end
I start out with the turtle grabbing value for "y" from a file, which in this case i had set up earlier with the value 32, then it does it's thing with it, moves, adds 32 to it a few times, then it writes it to the file, so that the next time i run the program, it picks up from where it left off on the size of the spiral. Where my problem is, is I want to write the value of "y" to the file, but obviously that gives an error when i just use file.write(y). What is the proper syntax for this?