[LUA] Table is false/nil? How is this possible?



function debug.getregistry().Entity:GetNetInt(id) then
     self.netInts = self.netInts or {}
     if not (self.netInts) print ("This shouldn't print") end
     return self.netInts[id]
end


In the above code, it prints “This shouldn’t print” and it also shows “attempt to index netInts, a nil value” on the third line.

Also, the following code crashes the client: I don’t know why.
while(!self.netInts) do self.netInts = {} end

I think a better question is, what are you trying to do? “net ints”, why would you do this when there’s already the net library and setnwint/getnwint + dtvars?

Try something like this

[lua]function ENTITY:GetGNWVar( StringID, Default )
local EntIndex = tostring( self:EntIndex() )

return GAMEMODE.GlobalData[ EntIndex ] and GAMEMODE.GlobalData[ EntIndex ][ StringID ] or Default

end[/lua]

My own library where you can remove Networked Variables when you want them to stay. I know, it might not make sense but I needed it.

I’m going to assume that the actual code you ran was syntactically correct.

I’ve seen LuaJIT do some funky impossible shit with for loops, so you can’t rule out a bug with LuaJIT. I find your method of function definition a little odd though, maybe you should do it in a more conventional way?

[lua]
local meta = FindMetaTable(“Entity”)
function meta:GetNetInt(id)
–blah blah code code
end
[/lua]

@Jcw87
That’s how I’m doing it :slight_smile:
But I had it like this:



Netty.ENT = FindMetaTable("Entity")
function Netty.ENT:GetInt(id)
end


Also, doesn’t LuaJIT get disabled? :confused:

The JIT compiler is disabled by default, but the LuaJIT interpreter is still used.

You should post code that has been tested and exhibits the problem instead of a re-typed untested snippet. Could be a simple typo that you aren’t noticing, or there could be a LuaJIT bug. You might also be doing something funky with metatables that is causing the problem. For instance, you said that ‘while(!self.netInts) do self.netInts = {} end’ crashes the client. The only thing I can think of that could cause that is if something is wrong with the __index or __newindex functions on the metatable of the object or table you are trying to assign the value to.

I would have, but the code wasn’t here, sorry about that.