Jump to content




Table name picker


  • You cannot reply to this topic
2 replies to this topic

#1 gheotic

  • Members
  • 64 posts
  • LocationDenmark

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



Quote

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 :)

#2 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 22 January 2013 - 07:01 AM

View Postgheotic, on 22 January 2013 - 06:39 AM, said:

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



Quote

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.

#3 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 22 January 2013 - 07:15 AM

View PostSuicidalSTDz, on 22 January 2013 - 07:01 AM, said:

View Postgheotic, on 22 January 2013 - 06:39 AM, said:

* 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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users