Jump to content




turtle quarry with restart after server shutdown

help turtle

  • You cannot reply to this topic
15 replies to this topic

#1 Cing

  • Members
  • 72 posts

Posted 07 April 2015 - 05: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/gkUuzUev
but now i only need a way to get this information back.

thanks in regards

#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 07 April 2015 - 06: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

#3 Cing

  • Members
  • 72 posts

Posted 07 April 2015 - 07:01 PM

thanks for the tip :)
But how do I write to a file and get the information back from the file?

#4 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 07 April 2015 - 07:17 PM

fs api

#5 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 08 April 2015 - 03:47 AM

View PostLupus590, on 07 April 2015 - 07:17 PM, said:

fs api

Err, to elaborate, you'd use the fs API (Wiki Page: http://computercraft...ki/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!


#6 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 08 April 2015 - 09:11 AM

View PostHPWebcamAble, on 08 April 2015 - 03:47 AM, said:

View PostLupus590, on 07 April 2015 - 07:17 PM, said:

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

#7 Cing

  • Members
  • 72 posts

Posted 08 April 2015 - 12:53 PM

thanks a lot HPwebcamable :D
and i get it lupus590 ;)

but can you also choose a line when writing and reading?

#8 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 08 April 2015 - 01: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 by Lupus590, 08 April 2015 - 01:05 PM.


#9 Cing

  • Members
  • 72 posts

Posted 08 April 2015 - 02:01 PM

oke get it thanks

#10 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 08 April 2015 - 03:32 PM

Just gonna leave this tutorial link here:Basic File IO

#11 Cing

  • Members
  • 72 posts

Posted 08 April 2015 - 04: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

#12 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 08 April 2015 - 04: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.

#13 Cing

  • Members
  • 72 posts

Posted 08 April 2015 - 04: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

#14 Cing

  • Members
  • 72 posts

Posted 08 April 2015 - 05:23 PM

View PostDragon53535, on 08 April 2015 - 04:26 PM, said:

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 by Cing, 08 April 2015 - 05:23 PM.


#15 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 08 April 2015 - 09: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?

#16 Cing

  • Members
  • 72 posts

Posted 09 April 2015 - 03: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users