Talk:G.pairs
From GMod Wiki
Entities not working with pairs?
I know it should, but I'm using
for i, TrGet in pairs(TrGets) do
where TrGets
is ents.FindInSphere()
with some variables.
I'm using it in a swep function. SWEP:Devestate()
But when I call things like TrGet:GetPos()
and TrGet:GetMaxHealth()
it seems to always return NIL even with if TrGet:IsNPC() then
before it.
And please excuse the strange variable naming method. I have a reason for it.
so for example
function SWEP:Devestate() -- Some needed code. local TrGets = ents.FindInSphere( StartPos, Radius ) -- Variables for i, TrGet in pairs(TrGets) do -- Debug Stuff if TrGet:IsNPC() then -- Debugging confirms it gets this far. The functions just don't work! -- Lots of code -- Including TakeDamageInfo because TakeDamage wasn't working. -- TakeDamageInfo isn't working, either... But doesn't return an error. elseif TrGet:IsPlayer() then -- Haven't Tested this yet. else -- Props. Haven't set this up yet. end end end
鬼【悪魔Ⓛucifer】★ 14:25, 4 October 2011 (PDT)
- Have you tried checking the table with PrintTable(TrGets)? It should be returning a sequential table with a single entity object linked to each key. This should work as you say the for loop starts looping through the table. If it gets this far, try doing print(type(TrGet)) to make sure the table is actually full of entities. Oh and please sign your name on talk pages, using ~~~~, thanks. 14:03, 4 October 2011 (PDT)
- Was gonna sign but I didn't remember how. If it isn't returning entities, how would I fix that? 鬼【悪魔Ⓛucifer】★ 14:25, 4 October 2011 (PDT)