• Access an entity table from both the server and the client
    5 replies, posted
Hello, I'm trying to make entities that store constants in an efficient way, thus far the best method I have found seems to be to utilize the entity's table. However, upon trying to optimize the code I made the unfortunate discovery that the entity tables seem to be unable to be accessed from any shared or clientside lua. The entity in question's code: [code] if SERVER then function ENT:Initialize() self:SetModel( "models/props_interiors/BathTub01a.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics self:SetSolid( SOLID_VPHYSICS ) -- Toolbox local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end self.LSClass = "Generator" self.GenType = "Energy" self.GenQuantity = "10" self.Linked = false self.LinkedTo = nil self.Active = false --self.Wattage = "Unavailable" end function ENT:Use( activator, caller ) return end else function ENT:Draw() self:DrawModel() end end [/code] These entities are designed to be linked to a central entity, who's entity table contains a table whereupon I store all the entitys that get linked to it. All the to-be-coded entity's have their constants defined in the above way. In my stool, I'm trying to access these constants declared by the entity's initialize: [CODE] function TOOL:LeftClick( trace ) local ent = trace.Entity if (!IsValid(ent)) or (ent:IsPlayer()) then return end if ent.LSClass and ent.LSClass != "node" then local index = table.Count( self.Objects ) local Phys = ent:GetPhysicsObjectNum( trace.PhysicsBone ) self:SetObject( index + 1, ent, trace.HitPos, Phys, trace.PhysicsBone, trace.HitNormal ) --works ent:SetColor(Color(0, 0, 255, 200)) end return true end [/CODE] However, ent.LSClass is returning nil. Is there either a similairly efficient methos I can use to store variables on these entities that is networked (The limit of 4 variables means network variables are undesirable as I cannot store a table on an entity) or is there a workaround in order to make the link stool work properly?
Is there a similair function to store a table? That way I could actually maintain my plethora of variables.
[QUOTE=Diggz;43509302]Is there a similair function to store a table? That way I could actually maintain my plethora of variables.[/QUOTE] You should rethink your design if you think you need to actually network an entire table.
I just need to be able to pull a variable from an entity. However every entity of that type needs it's own variant of that variable. I'm making a life support esque add on, and thus far I have every generator or storage unit storing a variable identifying it as one or the other. I would like to access that variable from the stool in order to tell whether or not it is a viable linkage candidate.
Sorry, you need to Log In to post a reply to this thread.