In Operator

Hello there, it’s me once again, this time around though I’m wondering on something regarding the usage of the in operator, so if I get something like a table, could I use;

[lua]

if(myVar in table) then
<logicHere>
end

[/lua]

Would it work?

Also more specifically, saying I want to use a list done by list.Set, can I access the variables by doing something like;




local myList=list.Get("ListName")

if(ply:GetVar("myKey") in myList==x) then

etc

end



would that work as well?

No, “in” can only be used in a for loop.

Then how would I get something from in a table then?

in pairs or in ipairs

[editline]27th October 2010[/editline]

or index it directly.

if table.HasValue(table2,myvar) then
//whatever
end

Also,please,don’t use “table” as a variable name,you’ll mess up everything.

This is how you make an iterating function, like pairs:

[lua]function range( s, e )
local i = s - 1
return function()
i = i + 1
if ( i <= e ) then return i end
end
end

for number in range( 5, 10 ) do
print( number )
end[/lua]


5
6
7
8
9
10