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

[Question] How do I update a variable is a running script then save the script with the new vairable

Started by Quinncunx, 06 June 2012 - 01:31 PM
Quinncunx #1
Posted 06 June 2012 - 03:31 PM
I am trying to write a script that will ask users for a password (similar to the tutorial on the wiki) with the difference that when it is run for the first time it asks the user to input their chosen password.

I am not really sure how to do this, I think there could be a solution by having the password saved to an external file to the script then read that in? Then the password could be changed as and when the user requires to do so, any advice and guidance would be greatly appreciated.

Thanks!
MysticT #2
Posted 06 June 2012 - 05:47 PM
I am not really sure how to do this, I think there could be a solution by having the password saved to an external file to the script then read that in? Then the password could be changed as and when the user requires to do so, any advice and guidance would be greatly appreciated.
That's exactly what you should do. Use the fs api to access the file to read/write the password.
kazagistar #3
Posted 06 June 2012 - 05:49 PM

local PASSFILE = "password.txt"

local file = fs.open(PASSFILE, "r")
if file then
  local password = file.readAll()
  file.close()
  -- verify user password here quit if wrong
else
  -- get a new password from user
  file = fs.open(PASSFILE, "w")
  file.write(password)
  file.close()
end
I wrote you some codings. :)/>/>
Quinncunx #4
Posted 06 June 2012 - 06:14 PM
Thanks Guys :)/>/>