Jump to content

Compare variable with table element


JeViCo

Recommended Posts

  • Moderators

I am not sure what you want to achieve with it. But if you want to check if an element is in a table, then this is also very fast method. The elements have become the KEY of the table.

local table = {[el1] = true, [el2] = true, [el3] = true}


if table[place] then
	-- Yes it is in the table
end


 

Adding elements to the table by hand:

table[el1] = true
table[el2] = true
table[el3] = true

 

 


 

With this method, you can also make a reference to different data:

local table = {[el1] = {"more data"}, [el2] = {"more data"}, [el3] = {"more data"}}

local moreData = table[place]

 

  • Like 1
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...