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

[SOLVED] How to make a program write to another program on a different line?

Started by CitricThunder, 18 September 2012 - 08:10 PM
CitricThunder #1
Posted 18 September 2012 - 10:10 PM
So i am using file:write to record the user, pass and admin status of my program. It only writes them on the first line of the program. I want the name on the first line, pass on the second and admin status on the third line. Is there anyway to do this?
Heres some of my code-


-- Part of detecting drive side
local driveSide
for _, side in ipairs(rs.getSides()) do
  if peripheral.isPresent(side) and peripheral.getType(side) == "drive" then
	driveSide = side
	break
  end
end
if driveSide then
  local file = io.open("/disk/Users", "w")
  print(file)
  file:write(""..name.."")  -- Trying to make them write on different lines. Only writes like "name""pass""admin"
  file:write(""..pass.."")
  file:write(""..admin.."")
  file:close()
  disk.eject(driveSide)
else
  term.setCursorPos(1,10)  -- Just fixing the GUI here
  term.clearLine()
  term.setCursorPos(1,10)  -- And here
  write("#")
  term.setCursorPos(50,10)  -- And here
  write("#")
  term.setCursorPos(12,14)
  error("No disk drive found.")
end
Luanub #2
Posted 18 September 2012 - 10:23 PM
Try using fs instead of io and use writeLine so..

  local file = fs.open("/disk/Users", "w")
  print(file)
  file.writeLine(""..name.."")  -- Trying to make them write on different lines. Only writes like "name""pass""admin"
  file.writeLine(""..pass.."")
  file.writeLine(""..admin.."")
  file.close()


If that don't work try using "a" instead of "w" which is append instead of write, It should automatically add the new data to the end of the file, but will leave all of the old.
GalactusX #3
Posted 18 September 2012 - 11:07 PM
when I programmed in Visual Basic, was simpler, write it all in one line, then, to go find a Shred, sought always in the 1st line to coincide with the data I was looking for, if it was, put the pointer at the end of the data sought, and carried the whole line, so it saves space and programming lines in the output file to save the information.

creates a function for write, and another to find and read, so no need to be creating more code, you just have to call this function when necessary, the program gains speed and memory space :)/>/>
CitricThunder #4
Posted 19 September 2012 - 09:54 PM
Try using fs instead of io and use writeLine so..

  local file = fs.open("/disk/Users", "w")
  print(file)
  file.writeLine(""..name.."")  -- Trying to make them write on different lines. Only writes like "name""pass""admin"
  file.writeLine(""..pass.."")
  file.writeLine(""..admin.."")
  file.close()


If that don't work try using "a" instead of "w" which is append instead of write, It should automatically add the new data to the end of the file, but will leave all of the old.

Thanks!