• [LUA] Table is false/nil? How is this possible?
    7 replies, posted
[code] 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 [/code] 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
[QUOTE=superdodo12;40784390][code] 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 [/code] 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[/QUOTE] 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]
[QUOTE=Lerpaderp;40784822]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?[/QUOTE] 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.
[QUOTE=superdodo12;40784390][code] 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 [/code] 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[/QUOTE] 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 :) But I had it like this: [code] Netty.ENT = FindMetaTable("Entity") function Netty.ENT:GetInt(id) end [/code] Also, doesn't LuaJIT get disabled? :/
[QUOTE=superdodo12;40786164]@Jcw87 That's how I'm doing it :) But I had it like this: [code] Netty.ENT = FindMetaTable("Entity") function Netty.ENT:GetInt(id) end [/code] Also, doesn't LuaJIT get disabled? :/[/QUOTE] 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.
Sorry, you need to Log In to post a reply to this thread.