Jump to content




[Solved] Error with self-updating script!

turtle api

5 replies to this topic

#1 BrunoZockt

  • Members
  • 56 posts
  • LocationGermany

Posted 22 July 2016 - 05:59 PM

HI Guys!
I have a really annoying Problem with a program I'm writing. The program is called "KI6" and is 3000 lines long and work perfect until today.
It's a program for mining turtles, to search Ores and of course: find back!
Yesterday I added the function that it updates itself, by starting another program, which deletes, and redownloads "KI6". Yesterday it worked fine, today it doesn't. When I start my program I get an Error: bios:367: [string "KI6"]:1: '=' expected.
The strange thing is, when I remove any letter in my Program, save, rewrite the letter and save again (obviously nothing changed) the program works!
Then I terminate it and try it again and get the Error again?! This makes absoloutly no sense to me, but maybe someone can help?
My whole program on pastebin: http://pastebin.com/gkz5sgZ8

The part I wrote yesterday:
function save(path, content)
local file = fs.open(path, "w")
file.writeLine(content)
file.close()
end
if fs.exists("database/OCM/updater") == false then
save("database/updater", "0")
end
file = fs.open("database/OCM/updater","r")
local fileData = {}
local line = file.readLine()
repeat
  table.insert(fileData, line)
  line = file.readLine()
until line == nil
file.close()
updated = fileData[1]
if updated == "0" then
  dead = 1
  if shell.run("OCM.updater") == false then
	term.clear()
	print("test")
	shell.run("pastebin get rUMt9siN OCM.updater")
	term.clear()
	print("loading...")
	shell.run("OCM.updater")
  end
end
if dead == 1 then
  return
end
save("database/OCM/updater", "0")

How the OCM.updater looks:
function save(path, content)
local file = fs.open(path, "w")
file.writeLine(content)
file.close()
end
shell.run("delete KI6")
shell.run("pastebin get gkz5sgZ8 KI6")
term.clear()
print("updating...")
save("database/OCM/updater", "1")
shell.run("KI6")

Pls help me, I'm really frustrated.
Sorry for bad english (I'm german)

EDIT: I found out what was wrong! It actually was an Error with automatic update and my text editor. Because, I accidently posted a wrong script onto pastebin where the Error occurs. So every time I started the program, it updated itself and started the now wrong script. But the script didn't get updated in my texteditor where I had opened the correct script. By removing and rewriting any letter in my texteditor, the correct script was saved again, and active again. So when I started the program again (this time it didn't load the wrong code from pastebin, because it knew that it updated right before) it worked. And after that it didn't work again because it updated to the wrong script again and so on and so on...
Thanks to anyone who tried to help, next time I will give all the information and a more Intelligent title to don't waste your time!

Bruno

Edited by BrunoZockt, 17 August 2016 - 09:43 AM.


#2 Luca_S

  • Members
  • 387 posts
  • LocationGermany

Posted 23 July 2016 - 11:33 AM

Tbh, I have no idea what your program does lol. Why do you need so many variables? What is the program supposed to do?

#3 BrunoZockt

  • Members
  • 56 posts
  • LocationGermany

Posted 23 July 2016 - 12:54 PM

It searches for ores, and the tricky thing: It finds its way back ^^
Every Variable from "a" to "zzz" saves one Step, and gets a value between 1 and 5 (1-left, 2-forward, 3-up, 4-down, 5-right), so the turtle finds back to the main floor.
However, I rewrote the last changes and it works now, don't know what the mistake was.
But I will write here again when I have another problem with this program.

Edit: As said in my awnser to valithor, I use tables now, so I don't have variables from "a" to "zzz" anymore but a simple table with different numbers of values, until endless. So the program isn't capped to 72 steps anymore, it can remember infinite steps!

Bruno

Edited by BrunoZockt, 17 August 2016 - 09:46 AM.


#4 loustak

  • Members
  • 7 posts

Posted 24 July 2016 - 07:32 AM

You shouldn't save every step in differents variables like this because it's... ugly.
What you can do is make a for loop who move forward the turtle and when you want it to back you just move backward.

#5 valithor

  • Members
  • 1,050 posts

Posted 24 July 2016 - 07:52 AM

View Postloustak, on 24 July 2016 - 07:32 AM, said:

You shouldn't save every step in differents variables like this because it's... ugly.
What you can do is make a for loop who move forward the turtle and when you want it to back you just move backward.

If he was dead set on using the sort of system he is currently using, he could use tables instead. There are advantages I see to using the kind of system he is using over a for loop, but in most cases a for loop would work.

#6 BrunoZockt

  • Members
  • 56 posts
  • LocationGermany

Posted 17 August 2016 - 09:34 AM

View Postvalithor, on 24 July 2016 - 07:52 AM, said:

View Postloustak, on 24 July 2016 - 07:32 AM, said:

You shouldn't save every step in differents variables like this because it's... ugly.
What you can do is make a for loop who move forward the turtle and when you want it to back you just move backward.

If he was dead set on using the sort of system he is currently using, he could use tables instead. There are advantages I see to using the kind of system he is using over a for loop, but in most cases a for loop would work.

I discovered tables 3 weeks ago and instantly knew that that's what I need. I changed my script from 3000 to 700 lines by that. You can simply use the same pastebin link to see it.
Thanks for your tipps anyways, if i wasn't on holiday they would have helped :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users