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

Player Detector code problem - Help please?

Started by AliveGhost, 12 April 2013 - 04:27 AM
AliveGhost #1
Posted 12 April 2013 - 06:27 AM
Hey!

I'm fairly new to CC, and am playing with FTB (like many), so have the MiscPeripherals addon. I'm currently playing on a server, and I have a quick program I wrote to only allow me through the door. However, I want to add a couple of people to be able to access the door. I tried doing "if b == "Shivy011" or "namehere" then
blah blah blah

but this seemed to let anyone in! So, if possible, I ask for your help. Here's the pastebin link, can anyone check it out and help me? http://pastebin.com/KSzxEy2v

Help would be greatly appreciated!

Thanks in advance

AliveGhost
zekesonxx #2
Posted 12 April 2013 - 08:29 AM

a, b = os.pullEvent()
You need to specify "player" as the event, otherwise any event can be captured here and things will be unhappy.


if b == "Shivy011" or "[color=#282828][font=helvetica, arial, sans-serif]namehere[/font][/color]" then
This is what is actually happening:

a, b = os.pullEvent("player")
#a = "player", b = "zekesonxx" (me)
if b == "Shivy011" or "namehere" then
code()
end
#The if statement is saying:
if b == "Shivy011"
#Which equals false, because Me != You
#The statement is then saying:
if "namehere"
#"namehere" is not "nil", nil, 0, or false so it returns true.
#Instead, do:
if b == "Shivy011" OR b == "namehere" then
(The comments above are C style comments, which Lua is unfriendly with but Prettify is happy with)
You could also use tables, but that's a different story.
GalactusX #3
Posted 29 June 2013 - 10:48 AM
hi all, i´m here again!!!

i play w player detector and make a program, I hope this program is useful

http://pastebin.com/XATYmqg7

I'm sorry if my English is very bad