Jump to content




Converting the fs.open() read into a string


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

#1 CaosTECH

  • Members
  • 131 posts
  • LocationIn your closet

Posted 31 October 2015 - 03:21 PM

Hey I am wondering on how to convert the fs.open() read into a string, here is my example of code but it doesn't work.
[/size]

if not fs.exists("file") then
file = fs.open("file", "w")
file.close()
end
write(":> ")
tx = read()
file = fs.open("file", "w")
file.write(tx)
file.close()
term.clear()
term.setCursorPos(1,1)
rFile = fs.open("file", "r")
txt = rFile.readAll()
print(txt)

[size=7]

But it does not print the text, I am creating a user custom username and password system using fs.open() and I can not get it to read the file and check if the user input = the files text

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 31 October 2015 - 03:40 PM

I tested your code and it works for me.

What CC version are you using? (this most likely isn't the problem)

Have you modified the FS API in any way?

Could you try out this code?
local file,content
if not fs.exists("file") then
  file = fs.open("file","w")
  write("New Name>")
  file.write(read())
  file.close()
end
file = fs.open("file","r")
content = file.readAll()
file.close()
write("Username>")
if(read() == content) then print("YAY") else print("NOPE") end

Edited by H4X0RZ, 31 October 2015 - 03:41 PM.


#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 31 October 2015 - 05:32 PM

That snippet would not work if ran more than once, because you do not close the file after reading the contents. Always close files as soon as possible!!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users