-4

I have this table:

maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}

How can I make a script so if 1702169 (for example) is picked from the table, it prints ''That's the number''?

Gelu
  • 121
  • 1
  • 2
  • 9

1 Answers1

1

The easiest way to do what (i think) you want is with pairs() function. This is a stateless iterator which you can read more about here: http://www.lua.org/pil/7.3.html

If you simply want to scan through the entire table and see if it contains a value, then you can use this simple code:

local maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}

local picked = 1702169

for i, v in pairs(maps) do
  if v == picked then
    print("That's the number")
    break
  end
end

The above code will iterate through the whole table where i is the key and v is the value of the table[key]=value pairs.

I am slightly unclear about your end goal, but you could create this into a function and/or modify it to your actual needs. Feel free to update your original post with more information and I can provide you with a more specific answer.

MrHappyAsthma
  • 6,332
  • 9
  • 48
  • 78