I think this is because of how metatables work. Basically each entity has a table associated with it, which is unique to that entity, each entity also has a metatable, but the metatable is just one table used for ALL entities.
When you index an entity (i.e. print(ent.GetWhatever)) it calls a function which does something like this (abbreviated a lot but you get the idea):
[lua]
function index( ent, key )
if metatable[ key ] then return metatable[ key ] end
if ent:GetTable()[ key ] then return ent:GetTable()[ key ] end
end
[/lua]
So you can see when you index for say, GetHealth, first it searches the main Entity metatable, it finds the C function GetHealth and returns that. When you index for say, GetTestName, it searches the main Entity metatable, [b]doesn't[/b] find any function, so it then searches the Entitys individual table, and finds the function NetworkVar created.
In short: just don't bother overwriting stuff.
You're right. Personally I think userdata elements should have priority over parent metatables, it should only fix problems like this. I'd probably just change the __index metamethod, unless Sublime has a built in file Find & Replace function ..
That's not how it works at all. It searches in the table you are indexing first, and if it doesn't find anything, [i]then[/i] it calls (or searches) __index.
[QUOTE=initrd.gz;40027325]That's not how it works at all. It searches in the table you are indexing first, and if it doesn't find anything, [i]then[/i] it calls (or searches) __index.[/QUOTE]
This is how I've always thought it worked, in the next update Garry moved the Entity index function to Lua, you can see it here: [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/extensions/entity.lua#L10[/url]
Sorry, you need to Log In to post a reply to this thread.