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

Multiple inputs in a single line

Started by Kotevski, 18 December 2015 - 04:38 AM
Kotevski #1
Posted 18 December 2015 - 05:38 AM
Ok so I have been trying to make my life much easier by creating a list but I can't find if such a thing is possible (Though I remember doing it in the past)

I wrote most of the code ingame on a server so I will try my best to summarize it here

while true do
rednet.open("right")
event, sendId, message = os.pullEvent()
if senderId == "14" or senderId == "26" or senderId == "27" and message == ("Example") then
redstone.setOutput("left", false)


So my question is: Is it possible to create a list of all of those ID's so that I don't have to type " or senderId == "" " each time I want to add another sender ID to the statement.

So for example something like this

if senderId == {"14", "26", "27" and message == ("Example") then

Thanks
Bomb Bloke #2
Posted 18 December 2015 - 06:10 AM
A table is the simple method:

local goodIDs = {[14] = true, [26] = true, [27] = true}

if goodIDs[senderID] then ...
Kotevski #3
Posted 19 December 2015 - 04:57 AM
A table is the simple method:

local goodIDs = {[14] = true, [26] = true, [27] = true}

if goodIDs[senderID] then ...

Using this throws back an error code that says
bios:14: [string "startup"]:1: '}' expected

For line 1 I have the following:

local goodIDs = {[14] = true, [26] = true, [27] = true, [34] = true, [35] = true, [36] = true, [37] = true}

I have no idea what the problem is
Dragon53535 #4
Posted 19 December 2015 - 06:48 AM
Are you sure that's exactly what the line says?
TheOddByte #5
Posted 20 December 2015 - 12:07 PM
A table is the simple method:

local goodIDs = {[14] = true, [26] = true, [27] = true}

if goodIDs[senderID] then ...
Alternatively he could use string indexes

local goodIDs = { ["14"] = true, ["26"] = true, ["27"] = true }

local id = read()
if goodIDs[id] then --# Check if the index exists in the table, eg 14, 26  or 27
    print( "The ID was valid" )
else
    print( "The ID was not valid!" )
end
Bomb Bloke #6
Posted 21 December 2015 - 12:20 AM
Indeed he could - but sender IDs are received as numbers, not strings. He'd need to go out of his way to convert them.