View Single Post
03-23-18, 10:27 AM   #3
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Originally Posted by doofus View Post
If I have this structure

mydata = { "one", "two", "three", "four" };

How do I iterate through it? How do I add a value if I want to?
in the example below the loop ranges from 1 to #mydata, which in your example is 4.
Lua Code:
  1. for i=1, #mydata do
  2.     if mydata[i] == "somevalue" then
  3.         print("bingo")
  4.     end
  5. end

Originally Posted by doofus View Post
if ( i == 51 ) then ... -- we do not have it, add it
mydata[51] = somevalue;
end

I am not intending to remove just to add and then at some time wipe the lot and start again.
you can e.g. add something if it doesn't exist in mydata
Lua Code:
  1. if not mydata["five"] then
  2.     --insert key "five" in mydata
  3.     tinsert(mydata, "five")
  4. end

Hope this is somewhat helpful to your situation.
  Reply With Quote