WoW:API tContains: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(new entry)
 
m (Move page script moved page API tContains to API tContains without leaving a redirect)
 
(One intermediate revision by one other user not shown)
Line 16: Line 16:
         end
         end
         return nil;
         return nil;
end


== Example ==
== Example ==

Latest revision as of 04:47, 15 August 2023

WoW Lua


tContains(table, value)

Returns true (1) if value is in table, false (nil) otherwise. Note: this is not a standard Lua function, but was added by Blizzard to simplify table searches.


Implementation

function tContains(table, item)
       local index = 1;
       while table[index] do
               if ( item == table[index] ) then
                       return 1;
               end
               index = index + 1;
       end
       return nil;
end


Example[edit]

banana = { "yellow", "curved", "yummy" };
lotus = { "pink", "pretty" };
eatme = tContains( lotus, "yummy" );

Result

eatme = false