JeViCo Posted February 7, 2018 Posted February 7, 2018 Hi everyone! I have some variables which i put in table like local table = {el1,el2,el3} how can i compare other variable through elements in table? like if place == el1 ?
XJMLN Posted February 7, 2018 Posted February 7, 2018 (edited) you can use ipairs/pairs loop: for i,v in pairs(table) do if place == v then -- some code end end or just use table[index] Edited February 7, 2018 by XJMLN
JeViCo Posted February 7, 2018 Author Posted February 7, 2018 i have a lot of variables to check in table. My event happens when player hit the marker, so it work several times
Moderators IIYAMA Posted February 7, 2018 Moderators Posted February 7, 2018 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] 1 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now