Jump to content




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


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

#1 CitricThunder

  • Members
  • 33 posts

Posted 18 September 2012 - 09: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


#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 18 September 2012 - 09: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.

#3 GalactusX

  • Members
  • 29 posts
  • Locationspain

Posted 18 September 2012 - 10: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 :)/>

#4 CitricThunder

  • Members
  • 33 posts

Posted 19 September 2012 - 08:54 PM

View Postluanub, on 18 September 2012 - 09:23 PM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users