dugasz1 Posted August 26, 2016 Share Posted August 26, 2016 Hello! How can i detect if a array's member exist or not? local array = { {"wathever", "wathever"}, {"wathever", "wathever"}, {"wathever", "wathever"}, } if(array[4] == nil) then --Do Something end Beacause this doesn't work. It throws attempt to index field error. Edit: I know i can count the table's lenght and check it but i want detect if Link to comment
zneext Posted August 26, 2016 Share Posted August 26, 2016 if ( array[4] ~= nil ) then or even if ( array[4] ) then will check if the index 4 exists. Link to comment
dugasz1 Posted August 26, 2016 Author Share Posted August 26, 2016 I tought it too but no somewhy. (I think it shouldn't matter but in my script it's a 3 dimension array but i guess it should work with a single variable) Link to comment
idarrr Posted August 28, 2016 Share Posted August 28, 2016 I try your code on http://www.lua.org/demo.html and it's working. Check your script, maybe there's another problem. Also try to loop through the table and print it after you add value on table, to check if the table is working or not. Link to comment
dugasz1 Posted August 29, 2016 Author Share Posted August 29, 2016 Today i tried it again and it worked. I don't know what was wrong last time. Thank you Link to comment
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