• net.WriteEntity() seems to be broken for me.
    4 replies, posted
So currently I'm making an economic addon for Garry's Mod, and one thing I'm using is a computer which allows people to interact with the new economy. However, for some odd reason net.WriteEntity decided to bugger itself whilst I was doing shit. function ENT:Use( activator, caller ) activator:ChatPrint(self.TermID) net.Start("openMenu") net.WriteEntity(self) net.Send(activator) end Here's the receive code: net.Receive("openMenu",function() LocalPlayer():ChatPrint(net.ReadEntity().TermID) CryptoTermMenu(net.ReadEntity()) end) And here's what appears in chat: One terminal ID, not a second like it's supposed to, also greeted with the error [ERROR] lua/entities/cryptos_computer/cl_init.lua:381: bad argument #1 to 'ChatPrint' (string expected, got nil)   1. ChatPrint - [C]:-1    2. func - lua/entities/cryptos_computer/cl_init.lua:381     3. unknown - lua/includes/extensions/net.lua:32 For some reason, when I change LocalPlayer():ChatPrint(net.ReadEntity().TermID) to LocalPlayer():ChatPrint(net.ReadEntity():GetClass()) it does print the Class of the entity (cryptos_computer), showing that the entity is going through, but not the custom defined variables, in this case .TermID and .GCrypto Is this a known error? Is there a way to fix it?
If you want to access the TermID and GCrypto, you will need to network those instead of the entity itself. Also if you don't want to use Net library to manualy network everything, you can use ENTITY/SetupDataTables.
I'm on mobile and can't see all of the code, but you definately should not be calling net.ReadEntity twice. What happens is that the first read is successful and reads the entity you sent, but the second tries to read a second entity that you did not send. You should store the entity in a local variable, and use that variable to operate on the entity.
Everytime I used SetupDataTables and NetworkVars every single entity would have the same data whereas I wanted the data to be specific to each instance of the entity. I'll go change that.
Glad it works now. Also, the Data Tables are uniqe for every instance of the entity, you must have done something incorretcly before.
Sorry, you need to Log In to post a reply to this thread.