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

Player Detector with multiple lines/arguments problem.

Started by DrTriGG3R, 07 August 2013 - 08:53 AM
DrTriGG3R #1
Posted 07 August 2013 - 10:53 AM
Hi,
Im on ComputerCraft 1.5 in the Direwolf20 1.4.7 Pack.
And my ingame name is "dennis190090"
I made a program with a door and a Player Detector for multiple users.
What happens is if the user, who is listed in the program presses the player detector, the door opens.
And if the user isnt listed, it should not open (is does now.., let me explain):
Picture in spoiler how the setup is:
Spoiler
3 Monitors
1 Computer
1 alarm
1 Iron door
1 Player Detector

And the complete code:
Spoiler
local Apass = "dennis190090"
local pass = "zorro132"
local pass = "aXed"
local pass = "lethal34"
local pass = "Gobblemewl"
local pass = "1mD4M14N"
local pass = "CrystalShotz"
local Rpass = "maartenT"
local monitor = peripheral.wrap("top")
local playerD = os.pullEventRaw("player")

if playerD ~= (Apass) or (pass) or (Rpass) then
  monitor.write("Acces Denied")
  rs.setOutput("back", true)
end

if playerD == (Apass) or (pass) then
  monitor.write("Acces Granted")
  rs.setOutput("right", true)
end

if playerD == (Rpass) then
  monitor.write("Ring the bells")
  rs.setOutput("right", true)
  rs.setOutput("back", true)
end

sleep(3)
rs.setOutput("right", false)
rs.setOutput("back", false)
os.reboot()
http://pastebin.com/V5KpuMu0

The Apass is just a "password" just like pass.
The Rpass is for our friend (Who we call retard).
The "or" between the "(Apass) or (pass)" is there because otherwise it wouldnt work somehow with multiple "local pass" (if the "(Apass)" was just a "(pass)" and there wasnt a "or")
e.g:
local pass = "name1"
local pass = "name2"
if playerD == (pass) then
  monitor.write("Acces Granted")
  rs.setOutput("right", true)
end
(This wont work somehow)

But now i ran into a problem: The computer always tells me "Acces deniedAcces Granted" and opens the door and rings the Alarm.. (No matter what, if the user is and isnt listed in the code)

What i want is when the user IS listed in the program, he can open the door.
When the user ISNT listed in the program, he wont be able to open the door and the alarm starts making noice)

Thanks!
Dennis.
Lyqyd #2
Posted 07 August 2013 - 07:46 PM
Split into new topic.

There are numerous problems with your code. One major issue is that you seem to think that a single variable can hold multiple values at once. It cannot. You can create a table instead, which can be made to do what you're looking for. You also don't need the parentheses, and you do need to explicitly compare each pair of variables instead of using or with no comparison, since your first if statement says, "If playerID does not equal Apass, or if pass is not equal to nil or false, or if Rpass is not equal to nil or false", which is always a true condition, since pass contains a value.
HurricaneCoder #3
Posted 09 August 2013 - 02:02 PM
I don't think you can do an (or) like that. Basically if you do (or) you have to do this:

if playerD ~= (Apass) or playerD ~= (pass) or playerD ~= (Rpass) then
– like that
reububble #4
Posted 10 August 2013 - 12:54 AM
This should be an easy to understand solution for your program.


local passes =
{"dennis190090","zorro132","aXed","lethal34","Gobblemewl","1mD4M14N",
"CrystalShotz"} -- this is a table that will store multiple names
local Rpass = "maartenT"
local monitor = peripheral.wrap("top")
local playerD = os.pullEventRaw("player")
local broken = false
for i=1,#passes do
  if playerD == passes[i] then
    monitor.write("Access Granted")
    rs.setOutput("right", true)
    broken = true
    break
  end
end
if not broken then -- only fired if access is not granted
    monitor.write("Access Denied")
    rs.setOutput("back", true)
end

if playerD == Rpass then
  monitor.write("Ring the bells")
  rs.setOutput("right", true)
  rs.setOutput("back", true)
end
sleep(3)
rs.setOutput("right", false)
rs.setOutput("back", false)
os.reboot()