72 posts
Posted 07 April 2015 - 06:01 PM
I have already looked for this problem and i found a post,
but there wasn't a clear answer to this problem.
So could please someone help.
I have already made a direction program
http://pastebin.com/gkUuzUevbut now i only need a way to get this information back.
thanks in regards
957 posts
Location
Web Development
Posted 07 April 2015 - 07:35 PM
Every time the turtle changes its position, you'd need to save the x,y, and z to a file
Then, when the turtle starts, you assume the turtle is starting at the position on the file
Alternatively, you could have a GPS server tower, and have the turtle find its location using that when it starts up
72 posts
Posted 07 April 2015 - 08:01 PM
thanks for the tip :)/>
But how do I write to a file and get the information back from the file?
2427 posts
Location
UK
Posted 07 April 2015 - 08:17 PM
fs api
957 posts
Location
Web Development
Posted 08 April 2015 - 04:47 AM
fs api
Err, to elaborate, you'd use the fs API (Wiki Page:
http://computercraft.info/wiki/Fs_%28API%29)
( Did you really need to post 5 letters? )
Here is an example:
local x = 1
local y = 2
local z = 42
--# Saving the coords to a file
local fileHandle = fs.open("path","w") --# fileHandle is just a varible, make it what you want, "path" is the path of the file, "w" means Write mode
fileHandle.writeLine(x) --# Writes x to the file, and goes to the next line
fileHandle.writeLine(y)
fileHandle.writeLine(z)
fileHandle.close() --# ALWAYS close() when you are done reading/writing! It saves the file, and does a few other things
--# Reading the file
local file = fs.open("path","r") --# decided to use 'file' instead of 'fileHandle', "r" is Read mode
x = file.readLine() --# We know the first line is the x pos
y = file.readLine() --# And the second is the Y
z = file.readLine() --# and z
file.close() --# Remember to close!
2427 posts
Location
UK
Posted 08 April 2015 - 10:11 AM
fs api
Err, to elaborate, you'd use the fs API (Wiki Page:
http://computercraft...ki/Fs_%28API%29)
posted this late last night, was ment to add or to it later, opps
72 posts
Posted 08 April 2015 - 01:53 PM
thanks a lot HPwebcamable :D/>
and i get it lupus590 ;)/>
but can you also choose a line when writing and reading?
2427 posts
Location
UK
Posted 08 April 2015 - 02:04 PM
if you want to read the 3rd line only, you will have to read and discard the 1st and 2nd
writing is a bit more complex, if you have a file with 5 lines, and wanted to edit the 3rd, you will have to read the whole file, then write the first 2 lines, your modified 3rd line then the last 2 lines
Edited on 08 April 2015 - 12:05 PM
72 posts
Posted 08 April 2015 - 03:01 PM
oke get it thanks
1080 posts
Location
In the Matrix
Posted 08 April 2015 - 04:32 PM
Just gonna leave this tutorial link here:
Basic File IO
72 posts
Posted 08 April 2015 - 05:22 PM
now i got another question
how can i check if the lines exists with fs.exists
and how can i delete all the lines at the and of my program
1080 posts
Location
In the Matrix
Posted 08 April 2015 - 05:26 PM
You're going to have to explain more. Are you meaning can you check how many lines are in a file? or if the file "lines" exists?
and for the second question, you're going to have to elaborate on that.
72 posts
Posted 08 April 2015 - 05:35 PM
i want a the beginning of the program check if there is informatie stored and if there is then it should go futher were it left
and at the end of the program i want to delete the information so it doesn't go back down again and dig
ps: sorry for my bad english
72 posts
Posted 08 April 2015 - 06:23 PM
You're going to have to explain more. Are you meaning can you check how many lines are in a file? or if the file "lines" exists?
i want to check if the lines exists
Edited on 08 April 2015 - 04:23 PM
7083 posts
Location
Tasmania (AU)
Posted 08 April 2015 - 10:43 PM
Do you want to check if a certain line exists within a certain file, or do you want to check if the whole file exists?
Do you want to delete some lines within a file, or do you want to delete the whole file?
72 posts
Posted 09 April 2015 - 04:13 PM
i wanted to see if the hole file exists.
But i already got it sorted out :D/>
i just used "fs.exists("path")
and "fs.delete("path") in my program.