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

Automated update program - whats wrong :(?

Started by compaman, 28 November 2013 - 09:09 AM
compaman #1
Posted 28 November 2013 - 10:09 AM
Long time ago i asked here how to make an "auto installer", now i want to make a complete update system…
I wrote the code and didn't got it working properly, so i decided to ask a pro again.
So I hope anyone can help me and tell me what i made wrong

The computer that broadcasts the update:

shell.run("clear")
local function drawmenu()
  --print("test")
  --sleep(3)
  local x = 1
  while x > 5 do
   print("")
   x = x + 1
  end
  print("	 Is the update for turtles or computer?")
  print("")
  print("")
  print("")
  if choose == "up" then
   print("	 >turtle<")
   print("")
   print("	  computer")
   forwhat = "turtle"
  elseif choose == "down" then
   print("	  turtle")
   print("")
   print("	 >computer<")
   forwhat = "computer"
  else
   print("	 >turtle<")
   print("")
   print("	  computer")
   forwhat = "turtle"
  end
end
local function menu()
while pressed == false do
local e,key = os.pullEvent( "key" )
if key == key.up then
  local choose = "up"
elseif key == key.down then
  local choose = "down"
end
drawmenu()
local e,enterkey = os.pullEvent( "key" )
if enterkey == key.enter then
  local pressed = true
end
end
end
local function update()
shell.run("clear")
local x = 1
while x > 5 do
print("")
x = x + 1
end
print("	   Whats the name of your update?:")
print("")
write("		")
local readFrom = read()
local file = fs.open(readFrom, "r")
local lines = file.readLine()
local program = {lines}
for lines in file.readLine do
table.insert(program, lines)
end
file.close()
local data = textutils.serialize(program, lines)
rednet.broadcast(forwhat, data)
end
menu()
update()

problems i recognized:
menu() function does not work for some reason :o/>/> (Look at the "test" message that just won't apear)
there're some problems with the file.readLine() part at the ending, checked it like a thousend times but I don't get whats wrong :(/>
Im sure there are tons of beginner mistakes, i'm sorry for that :$

Code for receiver


function testupdate()
if turtle then
  event, id, update, data = os.pullEvent()
  if event == "rednet_message" then
  if update == "turtle" then
   local writeTo = "myos"
   local system = textutils.unserialize(data)
   local file = fs.open(writeTo, "w")
   for i = 1,#system do
	file.writeLine(data[i])
   end
   print("installing update...")
   sleep(5)
   file.close()
  end
  end
else
  event, id, update, data = os.pullEvent()
  if event == "rednet_message" then
  if update == "computer" then
   local writeTo = "myos"
   local system = textutils.unserialize(data)
   local file = fs.open(writeTo, "w")
   for i = 1,#system do
	file.writeLine(data[i])
   end
   print("installing update...")
   sleep(5)
   file.close()
  end
  end
end
end
os.run("clear")
for n,m in ipairs(rs.getSides()) do rednet.open(m) end
testupdate()
  

Here i'm completly helpless, this doesn't work at all. The computer just sais "bios:337: expected string, string"
And here too, sorry for some beginner mistekas :D/>

At this point i'll just thank everyone who took the time to read this, and at the people who understood it or even know what i made wrong: I'll be even more thankfull when you write a comment :D/>
Edited on 28 November 2013 - 09:35 AM
Bomb Bloke #2
Posted 28 November 2013 - 05:19 PM
menu() function does not work for some reason :o/> (Look at the "test" message that just won't apear)

The menu() function loops until pressed is true, but under no circumstances will set it to true: And so it loops forever.

Here i'm completly helpless, this doesn't work at all. The computer just sais "bios:337: expected string, string"

You're not using os.run() correctly. shell.run() would be better suited to your purposes.

You get the ambiguous error message because it's not one of your functions erroring out, it's one of the default CC-included functions (but only because you called it incorrectly!). Ideally that command would tell you where it was called from, but since it doesn't, the key is to interspace print statements throughout your program to help you pinpoint where such errors are.