of     1   

ScottRhode
#141102414Monday, July 21, 2014 10:33 PM GMT

basically i have tables with true and false, like {false,false,false,false,false,true,false,fale) or {false,false,true,false,false,false,false) or {false,false,false,false,false,false,false,false) They are completely random, since it's what's genered by checking certain things. Now i want to check if a table has true atleast once, and execute code if it does. how?
blockoo
#141102551Monday, July 21, 2014 10:34 PM GMT

for i, v in pairs(table) do if v then --do stuff break end end
brinkokevin
#141102667Monday, July 21, 2014 10:35 PM GMT

do u need false ?? u could just put trues in the table and then if #table > 0 then print("True is there") else print("Nothing there") end if u do need false then u will need something like a check function function check(t) for i=1,#t do if t[i] then return true end end end check({false,false,false,true,false})
cntkillme
#141102808Monday, July 21, 2014 10:36 PM GMT

Iterate through it and check. for key = 1, #tbl do if tbl[key] == true then --do something break --so if it has other trues we don't do stuff again end end
blockoo
#141103126Monday, July 21, 2014 10:40 PM GMT

Mine is shortest :>
cntkillme
#141103330Monday, July 21, 2014 10:42 PM GMT

You should recount the amount of lines. Mine is 6 lines like yours but mine is faster in terms of speed and for what he wants, he isn't going to have non-numerical keys.
blockoo
#141103608Monday, July 21, 2014 10:45 PM GMT

Yours also has more characters in it, mine is still shortest. The difference in speed is negligible.
cntkillme
#141103784Monday, July 21, 2014 10:47 PM GMT

lol: for i=1,#table do if v[i]then --do stuff break end end
blockoo
#141103895Monday, July 21, 2014 10:48 PM GMT

That's better. I still prefer pairs though, since it's specifically designed for tables.
Relegated
#141105094Monday, July 21, 2014 11:00 PM GMT

for _,v in next, (tbl) do if v then --//: Code elseif not v then --//: Code end end Next > pairs
cntkillme
#141105402Monday, July 21, 2014 11:03 PM GMT

numerical > next > pairs > ipairs but in some cases numerical > ipairs > next > pairs (From fastest to slowest) All hail the lovely numerical loop pls
Relegated
#141105557Monday, July 21, 2014 11:04 PM GMT

never

    of     1