Posted 02 July 2013 - 06:34 PM
I've been making program which is supposed to wait for Player Detector event and let only certain players from the list in,
it has additional piece of code which reads how many users are listed on list (user per line), and here comes my problem.
Program seems to count lines correctly, but when I try to read lines again and apply them to custom variable array, I get nil variable when reading lines again.
So here is the code:
Is the reason maybe that I'm passing trought file when counting lines and when I'm trying to apply names, I am at the end of list and there's nothing to apply?
it has additional piece of code which reads how many users are listed on list (user per line), and here comes my problem.
Program seems to count lines correctly, but when I try to read lines again and apply them to custom variable array, I get nil variable when reading lines again.
So here is the code:
function openDoors()
redstone.setOutput("back",true)
sleep(3)
redstone.setOutput("back",false)
end
if not fs.exists("whitelist") then
error("File 'whitelist' not found!")
end
wl = io.open("whitelist", "r")
lc = 0
for line in wl:lines() do
lc = lc + 1
end
un={}
for i=1,lc do
un[i]=wl:readLine()
end
while true do
e, name = os.pullEvent("player")
for i=1,lc do
if name == un[i] then
print("Opening doors to player "..name)
openDoors()
name = nil
else
print("Player "..name.." tried to open the doors!")
end
end
end
and error code:
startup:19: attempt to call nil
Which indicates that there's an error at this piece of code:
un={}
for i=1,lc do
un[i]=wl:readLine() --ERROR
end
and I know, I tried using wl.readLine() instead of wl:readLine() but it works the same cause I use wl:lines() above in code and it isn't a problem.Is the reason maybe that I'm passing trought file when counting lines and when I'm trying to apply names, I am at the end of list and there's nothing to apply?