Ok, so i modified the program to print out the names on monitor 2, heres the code - getting a nil value error on line 8 :/ mind taking a look?
local redstoneDelay = 1 --#how long to keep redstone signals active
monList = peripheral.wrap("monitor_2") -
function display()
for i=1, #players do
local name = players[i].name
monList.setCursorPos(1,1)
if inWhiteList(name) == true then
monList.setTextColor(colors.lime)
monList.write(name)
--cX,cY = monList.getCursorPos()
--monList.setCursorPos(1,cY+1)
elseif inBlackList(name) == true then
monList.setTextColor(colors.red)
monList.write(name)
--cX,cY = monList.getCursorPos()
--monList.setCursorPos(1,cY+1)
else
monList.setTextColor(colors.orange)
monList.write(name)
--cX,cY = monList.getCursorPos()
--monList.setCursorPos(1,cY+1)
end
end
end
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#monList = peripheral.wrap("monitor_2")
--#Whitelisted People are true, black - false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["blackListPlaceHolder1"] = false
list["blacklistPlaceHolder2"] = false
local function inWhiteList(name) --#check if name is on whitelist
if list[name] == true then
return true --#name is on list
else
return false
end
end
local function inBlackList(name) --#check if name is on blacklist
if list[name] == false then
return true
else
return false
end
end
--#http://computercraft.info/wiki/Fs_%28API%29
local visitorLog --#file handle for recording visitor names to hard drive, allows future checking of who has visited
rs.setOutput("left", true) --#one time setups go outside of loops
if fs.exists("visitorLog") then
visitorLog = fs.open("visitorLog","a")
else
visitorLog = fs.open("visitorLog","w")
end
--#Main loop
while true do
--#I wish there was an event from the sensor I could pull here
--#Get players nearby
players = sensor.getPlayers()
--#expected table format, ... represents other data that we are not interested in
--#players = { 1 = {name = "player", ...}, 2 = { name = "player2", ...}
for i = 1, #players do --#for each player in range, check their name against the white and black lists
local name = players[i].name --#easier to type, a bit clearer too (IMO)
monitor.setCursorPos(1,1)
print(name)
if inWhiteList(name) then
visitorLog.writeLine("whitelist: "..name)
monitor.write("Hello, "..name.." Welcome to Robin And Adz base!")
rs.setOutput("left", false)
sleep(redstoneDelay)
rs.setOutput("left", true)
elseif inBlackList(name) then
visitorLog.writeLine("blacklist: "..name)
monitor.write("Hello, "..name.." You have 10 Seconds to leave")
--#i'm at a lost of what to do here
else --#name is not in either list
visitorLog.writeLine("not listed: "..name)
monitor.write("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
end
display()
end
visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end
Yes, i know i should have written the function after wrapping the peripherals and stuff but i didn't so… Ill move it later :P/> Also how can i go through the list(the list with all white listed/blacklisted players)
rather than getting players from the sensor for the display function?