Spoiler
The authorized file simply has the word "test" on the first line, though it still gives me access granted. Also it says "Access granted nil, welcome in!" rather than my username. Any ideas?
Program Not Reading File Correctly?
Started by popdog15, Oct 15 2013 05:45 PM
2 replies to this topic
#1
Posted 15 October 2013 - 05:45 PM
Here's my current code:
#2
Posted 15 October 2013 - 06:21 PM
You define "getTable" as a table, and you open the "authorised" file, but you still never load anything from the file into the table.
When your checkAuthority function first fails it calls itself without an arguement (note that having a function call itself is, in itself, generally bad practise). Because there's nothing in the table, and that second call doesn't give it a name to check against, it then compares nothing to nothing and finds them to be the same: "nil" hence gets welcomed to the system.
A somewhat improved table loader compared to the one I gave you earlier:
This creates one key in the table for each player in the file, named the same as those players.
Later, when you want to check if a given name exists in the table, you can simply perform:
I recommend reviewing some documentation about Lua tables. This should be a decent start.
When your checkAuthority function first fails it calls itself without an arguement (note that having a function call itself is, in itself, generally bad practise). Because there's nothing in the table, and that second call doesn't give it a name to check against, it then compares nothing to nothing and finds them to be the same: "nil" hence gets welcomed to the system.
A somewhat improved table loader compared to the one I gave you earlier:
local getTable = {}
.
.
.
local function loadTableFromFile()
local temp
local loadFile = fs.open("authorized", "r")
while true do
temp = loadFile.readLine()
if temp ~= nil then getTable[temp] = true else break end
end
loadFile.close()
end
This creates one key in the table for each player in the file, named the same as those players.
Later, when you want to check if a given name exists in the table, you can simply perform:
if getTable[player] then
print("You're authorised!")
else
print("I don't know you.")
end
I recommend reviewing some documentation about Lua tables. This should be a decent start.
#3
Posted 15 October 2013 - 06:30 PM
Bomb Bloke, on 15 October 2013 - 06:21 PM, said:
You define "getTable" as a table, and you open the "authorised" file, but you still never load anything from the file into the table.
When your checkAuthority function first fails it calls itself without an arguement (note that having a function call itself is, in itself, generally bad practise). Because there's nothing in the table, and that second call doesn't give it a name to check against, it then compares nothing to nothing and finds them to be the same: "nil" hence gets welcomed to the system.
A somewhat improved table loader compared to the one I gave you earlier:
This creates one key in the table for each player in the file, named the same as those players.
Later, when you want to check if a given name exists in the table, you can simply perform:
I recommend reviewing some documentation about Lua tables. This should be a decent start.
When your checkAuthority function first fails it calls itself without an arguement (note that having a function call itself is, in itself, generally bad practise). Because there's nothing in the table, and that second call doesn't give it a name to check against, it then compares nothing to nothing and finds them to be the same: "nil" hence gets welcomed to the system.
A somewhat improved table loader compared to the one I gave you earlier:
local getTable = {}
.
.
.
local function loadTableFromFile()
local temp
local loadFile = fs.open("authorized", "r")
while true do
temp = loadFile.readLine()
if temp ~= nil then getTable[temp] = true else break end
end
loadFile.close()
end
This creates one key in the table for each player in the file, named the same as those players.
Later, when you want to check if a given name exists in the table, you can simply perform:
if getTable[player] then
print("You're authorised!")
else
print("I don't know you.")
end
I recommend reviewing some documentation about Lua tables. This should be a decent start.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











