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

Table name picker

Started by gheotic, 22 January 2013 - 05:39 AM
gheotic #1
Posted 22 January 2013 - 06:39 AM
I am trying to make a script in Computercraft and misc perherial that detect what name the player has who is right clicking on the block(part of misc perherial mod)

is it possible to do something like this?
local Table1 = {arg1 ,"tilde1000", "thorsteingp", "Alex", "Amber", "Alice"}

if test == Table1 then
print("you may pass")
else
print("you cant pass")
end



function clear()
term.clear()
term.setCursorPos(1,1)
end
rednet.open("left")



while true do

event, playerName = os.pullEvent("player")

–print("Hello " .. playerName)

if playerName == "tilde1000" or playerName == "thorsteingp" or "player" then –If name = tilde1
clear()
print("Hello "..playerName)
print("you may pass")

rednet.broadcast("openGate")
print("open gate")
redstone.setOutput("top",true)
sleep(2)
redstone.setOutput("top",false)

rednet.broadcast("closeGate")
print("close gate")

else

redstone.setOutput("bottom",true)
sleep(2)
redstone.setOutput("bottom",false)
clear()
print("You do not have acceses!")
end
end


any help would be appreciated :)/>
SuicidalSTDz #2
Posted 22 January 2013 - 07:01 AM
I am trying to make a script in Computercraft and misc perherial that detect what name the player has who is right clicking on the block(part of misc perherial mod)

is it possible to do something like this?
local Table1 = {arg1 ,"tilde1000", "thorsteingp", "Alex", "Amber", "Alice"}

if test == Table1 then
print("you may pass")
else
print("you cant pass")
end



function clear()
term.clear()
term.setCursorPos(1,1)
end
rednet.open("left")



while true do

event, playerName = os.pullEvent("player")

–print("Hello " .. playerName)

if playerName == "tilde1000" or playerName == "thorsteingp" or "player" then –If name = tilde1
clear()
print("Hello "..playerName)
print("you may pass")

rednet.broadcast("openGate")
print("open gate")
redstone.setOutput("top",true)
sleep(2)
redstone.setOutput("top",false)

rednet.broadcast("closeGate")
print("close gate")

else

redstone.setOutput("bottom",true)
sleep(2)
redstone.setOutput("bottom",false)
clear()
print("You do not have acceses!")
end
end


any help would be appreciated :)/>

I use a variable system to detect the users allowed to login:

allowedUsers = "Notch","jeb_",dan200","SuicidalSTDz"
local event, playerName = os.pullEvent("player")
if playerName == allowedUsers then
–loginCode
else
–failedAttemptCode
end

I do not think you need a table.
Orwell #3
Posted 22 January 2013 - 07:15 AM
* big snip *

I use a variable system to detect the users allowed to login:

allowedUsers = "Notch","jeb_",dan200","SuicidalSTDz"
local event, playerName = os.pullEvent("player")
if playerName == allowedUsers then
–loginCode
else
–failedAttemptCode
end

I do not think you need a table.
That could never work. You do need a table for something like that and you do need to check for each key or value in the table (key is easiest).

local allowedUsers = {"Notch", "jeb_", "dan200", "SuicidalSTDz"}

local inverse = {}  -- this table will have the usernames as keys
for _,v in ipairs(allowedUsers) do
  inverse[v] = true
end

local event, playerName = os.pullEvent("player")
if inverse[playerName] then  -- check if the username is a key in the inversed table
--loginCode
else
--failedAttemptCode
end