This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BrunoZockt's profile picture

[Solved] Error with self-updating script!

Started by BrunoZockt, 22 July 2016 - 04:59 PM
BrunoZockt #1
Posted 22 July 2016 - 06: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 on 17 August 2016 - 08:43 AM
Luca_S #2
Posted 23 July 2016 - 12:33 PM
Tbh, I have no idea what your program does lol. Why do you need so many variables? What is the program supposed to do?
BrunoZockt #3
Posted 23 July 2016 - 01: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 on 17 August 2016 - 08:46 AM
loustak #4
Posted 24 July 2016 - 08: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.
valithor #5
Posted 24 July 2016 - 08:52 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.

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.
BrunoZockt #6
Posted 17 August 2016 - 10:34 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.

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/>