This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Robinlemon's profile picture

SensorLog - Logging nearby players printing as a table.

Started by Robinlemon, 12 May 2015 - 02:37 PM
Robinlemon #1
Posted 12 May 2015 - 04:37 PM
I want the program to return the results from the sensor(returns as a table)
and then print the usernames from the table into the monitor nearby, it should check for new players every 1 second. Im currently printing the names and it returns as a table.

Code:


--Wrapping
sensor = peripheral.wrap("left")
monitor = peripheral.wrap("right")
--Whitelisted People
whitelist = {"Robinlemon_","Adz999"}
--Blacklisted People
blacklist = {"Izok_"}
--Main loop
while true do
   sleep(1)
   --Get players nearby
   players = sensor.getPlayers()
   for num,name in pairs(players) do
	  print(name)
   end
end

It outputs this:

KingofGamesYami #2
Posted 12 May 2015 - 04:40 PM
Use textutils.serialize(name) and print the result. This'll show how the table is structured, so you can access the appropriate key for the username.
Robinlemon #3
Posted 12 May 2015 - 05:01 PM
Use textutils.serialize(name) and print the result. This'll show how the table is structured, so you can access the appropriate key for the username.

Thanks, but still a little confused for example how can i extract the name from the table? do i just serialize it then print it?

Use textutils.serialize(name) and print the result. This'll show how the table is structured, so you can access the appropriate key for the username.

Thanks, but still a little confused for example how can i extract the name from the table? do i just serialize it then print it?
Use textutils.serialize(name) and print the result. This'll show how the table is structured, so you can access the appropriate key for the username.

http://i.imgur.com/eH3wROw.png Is what it outputs, how can I just print the name?
Creator #4
Posted 12 May 2015 - 05:10 PM
make something like:


for i,v in pairs(generalTable) do
    print(v.name)
end
Robinlemon #5
Posted 12 May 2015 - 05:10 PM
Ahah! I got it to work :)/> I did print(name["name"]) :D/> Thanks for the help!
Creator #6
Posted 12 May 2015 - 06:14 PM
You are welcome ;)/>
Robinlemon #7
Posted 12 May 2015 - 08:52 PM
Sorry for double posting, but because of the major update I decided that this would need a whole new topic!

If anyone can help compact this, that would be great! theres also a few bugs ive been working through but I feel like someonelike Lyqyd could find them in seconds xD

My new updated code:


--Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--Whitelisted People
local whitelist = {}
print("Declared Whitelist")
whitelist["Robinlemon_"] = true
whitelist["Adz999"] = true
--Blacklisted People
local blacklist = {}
print("Declared Blacklist")
blacklist["lol.png"] = true
--Main loop
while true do
   rs.setOutput("left", true)
   --Get players nearby
   players = sensor.getPlayers()
   for num,name in pairs(players) do
	  monitor.setCursorPos(1,1)
	  if name[name] ~= null then
		 print(name[name])
		 if name[name] == "Robinlemon_" or "Adz999" then
			monitor.write("Hello, "..name["name"].." Welcome to Robin And Adz base!")
			rs.setOutput("left", false)
		 else
			rs.setOutput("left", true)
		
		 for 1,i #name in pairs do
			if name[name] == blacklist[i] then
				print("Hello, "..name[name].." You have 10 Seconds to leave")
			monitor.write("Hey "..name[name]..", You're in neutral territory, to get access ask Robin or Adz")
		
	  else
		 monitor.clear()
	  end  
   end
end

Long code short, this should scan for nearby players, if the player is on the whitelist then the rs signal on the left side should turn off and it should output to the monitor a text holder which ill edit later, if the player is on the blacklist it should output to the monitor: "Hey "..name..", You have 10 seconds to leave." the 10 will countdown till 0, if they are on neither the rs signal should stay on and they should not be given a countdown and should ouput a textholder to the monitor which ill edit later.

For the people that dont want to read that ^ a table my favourite -_-/>



Thanks for all the help guys, you're amazing ^-^
<3
Edited on 12 May 2015 - 06:54 PM
Lupus590 #8
Posted 12 May 2015 - 10:31 PM
I would make functions for checking if a name is on the black/white list and returns a bool (true or false) if the name is or is not in the list

call that function in an if statement to decide which redstone to change state (if either)

I'm going to add some code in here soon

these are the function I suggested
local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[name] == true then
	return true --#name is on list
  else
	return false --#name is not on list (or whitelist[name] == false)
  end
end

local function inBlackList(name) --#check if name is on blacklist
	if blacklist[name] == true then
	return true
  else
	return false
  end
end

I can't figure out how your sensor works by reading your code, also I think that you may be accessing the returned player data in an incorrect way
this concern is caused by one of your variables being name[name] (do you mean: name.name or name["name"] (both of these are the same), you are going to cause an error)

I will add my full solution to this soon
can't do that until I know how to use the sensor
Edited on 12 May 2015 - 09:17 PM
Lyqyd #9
Posted 12 May 2015 - 10:40 PM
Threads merged. Please stick to one topic for a given program. Feel free to update the topic title to reflect the nature of the current question.
Robinlemon #10
Posted 12 May 2015 - 11:00 PM
I would make functions for checking if a name is on the black/white list and returns a bool (true or false) if the name is or is not in the list

call that function in an if statement to decide which redstone to change state (if either)

I'm going to add some code in here soon

these are the function I suggested
local function onWhiteList(name) --#check if name is on whitelist
  if whitelist[name] == true then
	return true --#name is on list
  else
	return false --#name is not on list (or whitelist[name] == false)
  end
end

local function onBlackList(name) --#check if name is on blacklist
  if blacklist[name] == true then
	return true
  else
	return false
  end
end
Whitelist/Blacklist functions sorted :)/>/>/> Why local functions?

Threads merged. Please stick to one topic for a given program. Feel free to update the topic title to reflect the nature of the current question.

Thanks Lyqyd, you're the best ;)/>
Edited on 12 May 2015 - 08:59 PM
Robinlemon #11
Posted 13 May 2015 - 07:52 AM
I will add my full solution to this soon
can't do that until I know how to use the sensor

Wrap the sensor then do <sensor>.getPlayers() it returns a list of usernames in the area, printed as a table like the following {1.0={name="Robinlemon_",uuid="accac……."}}
Edited on 13 May 2015 - 05:54 AM
Lupus590 #12
Posted 13 May 2015 - 09:24 AM
your variable names are poorly chosen then (IMO), good variable names are descriptive of their contents

I'll post a working solution soon

while doing anything after the 10 seconds on the black list is not done, this should work

local redstoneDelay = 1000 --#how long to keep redstone signals active
						   --#if this controls a door, the visitor needs enough time to get through
						   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false
 

local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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 = fd.open("visitorLog","a")
else
  visitorLog = fd.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 = player[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
    end
  end 
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end
Edited on 13 May 2015 - 08:00 AM
Robinlemon #13
Posted 13 May 2015 - 03:29 PM
your variable names are poorly chosen then (IMO), good variable names are descriptive of their contents

I'll post a working solution soon

while doing anything after the 10 seconds on the black list is not done, this should work

local redstoneDelay = 1000 --#how long to keep redstone signals active
						   --#if this controls a door, the visitor needs enough time to get through
						   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false


local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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 = fd.open("visitorLog","a")
else
  visitorLog = fd.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 = player[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
    end
  end 
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end

Omg Thanks dude! :)/> This is awesome!
Robinlemon #14
Posted 13 May 2015 - 04:16 PM
Damnit, a nil value :/
Lupus590 #15
Posted 13 May 2015 - 04:55 PM
opps, fs not fd

full code with fix

local redstoneDelay = 1000 --#how long to keep redstone signals active
												   --#if this controls a door, the visitor needs enough time to get through
												   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false

local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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 = player[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
    end
  end
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end
Robinlemon #16
Posted 13 May 2015 - 06:47 PM
opps, fs not fd

full code with fix

local redstoneDelay = 1000 --#how long to keep redstone signals active
												   --#if this controls a door, the visitor needs enough time to get through
												   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false

local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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 = player[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
	end
  end
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end

Thanks, but oh god am i an idiot, even i could have spot that!
Robinlemon #17
Posted 13 May 2015 - 06:54 PM
:(/> Also the same error on line 44





I think you need to check that the data is true before indexing, for example


a = 0
if a > 0 then
   print("Larger than 0!")
else
   print("Not larger than 0!")
Lupus590 #18
Posted 13 May 2015 - 06:55 PM
players not player

full code with fix (again)

local redstoneDelay = 1000 --#how long to keep redstone signals active
																								   --#if this controls a door, the visitor needs enough time to get through
																								   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false
local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
    end
  end
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end
Robinlemon #19
Posted 13 May 2015 - 07:00 PM
players not player

full code with fix (again)

local redstoneDelay = 1000 --#how long to keep redstone signals active
																								   --#if this controls a door, the visitor needs enough time to get through
																								   --#measured in milliseconds (1000 = 1 second)
--#Wrapping
sensor = peripheral.wrap("top")
monitor = peripheral.wrap("monitor_1")
--#Whitelisted People are true, black false
local list = {}
list["Robinlemon_"] = true
list["Adz999"] = true
list["lol.png"] = false
list["test"] = false
local function inWhiteList(name) --#check if name is on whitelist
  if whitelist[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 blacklist[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.print("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.print("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.print("Hey "..name..", You're in neutral territory, to get access ask Robin or Adz")
	end
  end
  visitorLog.flush() --#I've liked the fs api wiki page, if you don't understand this part
end

Thanks, and this just makes me even more idiotic xD
Lupus590 #20
Posted 13 May 2015 - 07:22 PM
don't worry, I've done it too
sometimes you just need a fresh pair of eyes
Edited on 13 May 2015 - 05:23 PM
Robinlemon #21
Posted 13 May 2015 - 07:55 PM
don't worry, I've done it too
sometimes you just need a fresh pair of eyes

Do you know how to fix it?
Lupus590 #22
Posted 13 May 2015 - 08:39 PM
Yes, I managed to fix it. Before we get too far off topic, how's your code?
Edited on 13 May 2015 - 06:40 PM
Robinlemon #23
Posted 13 May 2015 - 09:06 PM
Not too bad, still trying to figure out that error xD
Lupus590 #24
Posted 13 May 2015 - 09:24 PM
which error?
Robinlemon #25
Posted 13 May 2015 - 09:52 PM
which error?

Oh weird, it didn't post

Error on line 44, the nil error, I think you have to check whether the players variable has data

:(/>/>/>/> Also the same error on line 44






I think you need to check that the data is true before indexing, for example


a = "Stringy!"
if a ~= nil then
   print("Data!")
else
   print("No Data!")
end
This ^
Edited on 13 May 2015 - 07:54 PM
Lupus590 #26
Posted 13 May 2015 - 10:30 PM
get the players table to print, tell me whats in it
Robinlemon #27
Posted 14 May 2015 - 03:51 PM
Ok nevermind, i fixed it :D/>

Now…
How can i have a second monitor else where that has the list of name

Robinlemon_ –#green text representng whitelisted
test1 –#Yellow text representing neutral/unwhitelisted
test2 –#Red representing blacklisted

If you click there name(I may use DW20's button API or most likely touchpoint) there name changes colour

I can do all the above, but how can i make it so i can just change it and it will update?

Would i need to use fs.read() etc so theres a whitelist file and a blacklist file? if so how would I do such a thing?

also how can I have another monitor which is always reading visitorLog?

Now looking at fs :)/>
Lupus590 #28
Posted 14 May 2015 - 04:30 PM
just wrap a second monitor like you did the first one (you don't have to name the returned peripheral handle as monitor, you can use any name (like variables))

as for button API's, I'd pick touchpoint as help is more available.
for using the API, make a test script which just draws a button. play around with the API until you are confident to use it in your project, and remember: the source is the best documentation
reading files from disk will use fs API once again, play around in a testing script so you don't mess up your project
Edited on 14 May 2015 - 02:30 PM
Robinlemon #29
Posted 14 May 2015 - 04:34 PM
Ok, is there anyway to make it just text and no box around it?

I think ima just write my own program and see how it goes
Robinlemon #30
Posted 14 May 2015 - 05:13 PM
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?
Lupus590 #31
Posted 14 May 2015 - 05:38 PM
your error is because lua doesn't know what the function inWhiteList means yet

when the computer reads code, it does it once, if it doesn't know what something is, it will error

move the functions above your new code so that you explain to lua what things are before asking it to use them
Robinlemon #32
Posted 14 May 2015 - 05:46 PM
your error is because lua doesn't know what the function inWhiteList means yet

when the computer reads code, it does it once, if it doesn't know what something is, it will error

move the functions above your new code so that you explain to lua what things are before asking it to use them

ahh ok
Robinlemon #33
Posted 14 May 2015 - 08:25 PM


Got it to work, how can i go through the list with a for loop and do it for each of them?
I want them after each other
Lupus590 #34
Posted 14 May 2015 - 08:59 PM
put the buttons in a table with a numeric index
loop through the table

for i = 1, #buttonTable do
  buttonTable[i].draw()
end
Robinlemon #35
Posted 14 May 2015 - 11:29 PM
put the buttons in a table with a numeric index
loop through the table

for i = 1, #buttonTable do
  buttonTable[i].draw()
end

No I mean like use the current table I'm using to determine whether people are in the whitelist or not
It should print all the people in that list beneath each other written in the correct colour and anyone new that comes to my base should be added to that list too
Edited on 14 May 2015 - 09:31 PM
Lupus590 #36
Posted 14 May 2015 - 11:39 PM
I'm going to take the training wheels off a bit here:

for key,value in pairs(yourTable) do
  print(key..": "..tostring(value))
end
have a play around with that
Edited on 14 May 2015 - 09:40 PM
Robinlemon #37
Posted 14 May 2015 - 11:42 PM
I'm going to take the training wheels off a bit here:

for key,value in pairs(yourTable) do
  print(key..": "..tostring(value))
end
have a play around with that

So for every key it prints it's values in the format key: value
Lupus590 #38
Posted 14 May 2015 - 11:58 PM
yep, you should be able to use that to get the names out of the list (key) and decide whether they are in the black or white (value)

I'm purposely being a bit ambiguous to get you to do most of the thinking (it's a teaching technique - I think)
Robinlemon #39
Posted 15 May 2015 - 07:55 AM
yep, you should be able to use that to get the names out of the list (key) and decide whether they are in the black or white (value)

I'm purposely being a bit ambiguous to get you to do most of the thinking (it's a teaching technique - I think)

Lol, ok xD
Lupus590 #40
Posted 15 May 2015 - 09:01 AM
you said that you want it to add people to the list when they are introduced to the system, you will need to save the table to a file or it will be lost when the computer reboots (which happens each time it's chunk is unloaded)
Robinlemon #41
Posted 15 May 2015 - 06:40 PM
you said that you want it to add people to the list when they are introduced to the system, you will need to save the table to a file or it will be lost when the computer reboots (which happens each time it's chunk is unloaded)

Will do, but chunk loaded :)/> but the server restarts every 6 hours so ill have to save to a file

Havign a bit of trouble getting it to work but i found some intresting things
Lupus590 #42
Posted 15 May 2015 - 07:02 PM
what's giving you trouble and what's so interesting?
Robinlemon #43
Posted 16 May 2015 - 11:12 PM
what's giving you trouble and what's so interesting?

Never mind I think I may have worked it out
Robinlemon #44
Posted 29 May 2015 - 12:49 AM
what's giving you trouble and what's so interesting?

Ok, worked a lot of it out, been a long time - started to work on that list again seems impossible, just going to make a manual list that it will print and modify lyqyds toucpoint api to my needs.