Posted 08 October 2013 - 09:24 PM
Not sure what's going on here.
Edit: Sorry, I forgot to mention what the program was. It's a security program that'll be using a player detector, and outputting if the player is able to access it or not via a speaker. (I've not implemented the speaker speaking yet.) The way I'm trying to make it go is, player hits player detector, program checks if their name is on a line of the "authorized" file, if it is, it'll let em' through. If not, it won't.
It doesn't print anything past "test". I'll right click the player-detector, and then it simply restarts. The reason I do serialize and then unserialize is because I don't know how to read a file and directly make it a table.
Edit: Sorry, I forgot to mention what the program was. It's a security program that'll be using a player detector, and outputting if the player is able to access it or not via a speaker. (I've not implemented the speaker speaking yet.) The way I'm trying to make it go is, player hits player detector, program checks if their name is on a line of the "authorized" file, if it is, it'll let em' through. If not, it won't.
-- sets up stuff
-- put your allowed players here:
allowedPlayers = {"popdog15"}
pd = peripheral.wrap("right") -- pd = playerdetector
speaker = peripheral.wrap("top")
print("test")
function checkFile()
if fs.exists("authorized") == true then
useFile()
print("Authorized file existing already.")
else
openThat = fs.open("authorized", "w")
openThat.close()
print("Authorized player file created!")
end
end
function useFile()
loadFile = fs.open("authorized", "r")
local getPlayers = textutils.serialize(loadFile.readAll())
local getTable = textutils.unserialize(getPlayers)
loadFile.close()
print("Got table!")
end
while true do
function getEvent()
eventData = {}
eventData = os.pullEvent()
if eventData[1] == "player" then
checkAuthority(eventData[2])
print("Checking authority!")
end
end
function checkAuthority(player)
if getTable[player] == true then
allowIn()
print("allowed!")
else
deny()
print("Access denied!")
end
end
end
checkFile()
It doesn't print anything past "test". I'll right click the player-detector, and then it simply restarts. The reason I do serialize and then unserialize is because I don't know how to read a file and directly make it a table.