Hey, a bit of a stupid question, so I'm trying to make a 'user' creator that when you input a name, it checks a file that has a full list of all the currently created user names, to prevent duplicates, and if it doesn't then it adds it to the file later when creating the account, but I can't figure out how to search the file for the string, any help?
0
Reading Files to check for word.
Started by Waterspark63, Jun 18 2018 01:30 PM
1 reply to this topic
#1
Posted 18 June 2018 - 01:30 PM
#2
Posted 19 June 2018 - 02:45 AM
The easy way is to put your usernames in a table:
You can then save / load this table using textutils.serialise() / textutils.unserialise():
local usernames = {["Waterspark63"] = true, ["Bomb Bloke"] = true} print("Enter a username:") local user = read() if usernames[user] then -- Username exists else -- Username does not exist end
You can then save / load this table using textutils.serialise() / textutils.unserialise():
-- Save table: local outFile = fs.open("users.txt", "w") outFile.writeLine( textutils.serialise( usernames ) ) outFile.close() -- Load table: local inFile = fs.open("users.txt", "r") local usernames = textutils.unserialise( inFile.readAll() ) inFile.close()
Edited by Bomb Bloke, 19 June 2018 - 02:46 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users