local i = 1
function open()
rs.setBundledOutput("left", colors.orange)
sleep(.4)
rs.setBundledOutput("left", 0)
sleep(.4)
end
function close()
rs.setBundledOutput("left", colors.white)
sleep(.4)
rs.setBundledOutput("left", 0)
sleep(.4)
end
function elevatorUp()
rs.setBundledOutput("left", colors.magenta)
sleep(.4)
rs.setBundledOutput("left", 0)
sleep(.4)
end
peripheral.wrap("right")
while true do
event, playerName = os.pullEvent("player")
print(playerName)
if playerName == ("dobbylego") or ("steve921") then
--This is the part that runs when the correct people click the player detector.
print("Accepted")
open()
open()
open()
sleep(2.0)
close()
close()
close()
else
--This is what runs when the wrong person click the player detector.
print("Denyed")
repeat
elevatorUp()
i = i + 1
until i == 13
end
end
Player Detector Problems
Started by dobbylego, May 22 2013 10:51 PM
5 replies to this topic
#1
Posted 22 May 2013 - 10:51 PM
When I run this startup program and I click on the block the program runs flawlessly but as soon as someone else not dobbylego or steve921 clicks it the program also runs like it was the correct person. Does anyone know how to make it so only specified people can make the program run?
#2
Posted 22 May 2013 - 11:24 PM
with if statements we cannot say this
the reason is, that because of the way programming works, particularly in Lua, a value results in true, and you're giving that if statement a value i.e. "steve921". So even if the first conditional in the statement is false, the entire thing will return true because of the following rule with boolean OR logic.
if playerName == ("dobbylego") or ("steve921")
we must instead say thisif playerName == "dobbylego" or playerName == "steve921"
the reason is, that because of the way programming works, particularly in Lua, a value results in true, and you're giving that if statement a value i.e. "steve921". So even if the first conditional in the statement is false, the entire thing will return true because of the following rule with boolean OR logic.
Quote
true OR true = true
true OR false = true
false OR true = true
false OR false = false
true OR false = true
false OR true = true
false OR false = false
#3
Posted 22 May 2013 - 11:40 PM
Ok cool thanks! So it was bacsicly saying that if it is clicked then its runing the program? Thanks!
Oh one last thing.. is there a way to make it so that it can read names off of a list in another program for all of the people alowed? Would it just be
Oh one last thing.. is there a way to make it so that it can read names off of a list in another program for all of the people alowed? Would it just be
if playerName == "dobbylego" if playerName == "name1" if playerName == "name2"
#4
Posted 22 May 2013 - 11:52 PM
Yes that's possible.
Have a look at the FS Api in the wiki to see how you can write files and read them.
Have a look at the FS Api in the wiki to see how you can write files and read them.
#5
Posted 22 May 2013 - 11:54 PM
yes it is possible by using tables.
this is a method using the same program...
if you define something like this at the top of the program
then make your if statement to this
to use another program you would want to look into using os.loadAPI and then you can access all variables and functions from that program that aren't marked local.
this is a method using the same program...
if you define something like this at the top of the program
allowedPlayers = {
["dobbylego"] = true,
["name1"] = true,
["name2"] = true,
-- etc, etc, etc ... just make sure you have == true
}
then make your if statement to this
if allowedPlayers[playerName] then
to use another program you would want to look into using os.loadAPI and then you can access all variables and functions from that program that aren't marked local.
#6
Posted 23 May 2013 - 12:15 AM
Thank you! Both of you! It is working flawlessly!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











