Is there an equivalent method for table.HasValue(), but with keys?
5 replies, posted
Basically yeah. If I want to compare a key with data, is that possible? I looked through the table library and didn't find anything that jumped out at me, but maybe I'm misunderstanding. I'd rather not do a "for" loop if possible ,just to save on cycles, as I'll be running this logic fairly often.
[code]
function table_hasKey( tbl, key )
for k,v in pairs(tbl) do
if k==key then
return true
end
end
return false
end
[/code]
it's not that hard...
Arg. I was hoping I wouldn't have to do that. guess that's what I have to do though. I was hoping there was an existing way to do it, thanks for the help anyways.
[QUOTE=CallMePyro;43071338]Arg. I was hoping I wouldn't have to do that. guess that's what I have to do though. I was hoping there was an existing way to do it, thanks for the help anyways.[/QUOTE]
It's no different, than creating your own function. It may even run faster then the global function if you localize it. (don't quote me on this I don't know very much about lua's speed)
what
[lua]if tbl[key] ~= nil then[/lua]
or am i missing something?
[QUOTE=CapsAdmin;43071377]what
[lua]if tbl[key] ~= nil then[/lua]
or am i missing something?[/QUOTE]
[IMG]http://data2.whicdn.com/images/23158983/Patrick-+I+love+you_thumb.jpg[/IMG]
Sorry, you need to Log In to post a reply to this thread.