Entity method argument sending as nil?

I have an entity which I need to send a umsg with. The only way i seem to be able to achieve this with is if I do a normal method like so:

function sendInfo(argString) 


Which works just fine if I call it like so:


However, if I change the sendInfo method to:

function ENT:sendInfo(argString)


Then anything that gets passed through the argument is nil. Is this because my MyString is declared like so:

ENT.MyString = "nothing"

It has a value before sending. What can I do to make it work?

Show us how you’re actually calling ENT:senfInfo

function ENT:StartTouch( hitEnt )

Thats the way I call it to replicate the problem.

You’re supposed to use colons when calling methods.

ent.Stuff( ent )

is the same as


And when you declare a function with the colon operator (a method) then it automatically assigns the 1st argument as being “self” and thus you must call it again with the colon operator if you want it to automatically set itself as the first parameter.

[editline]1st December 2013[/editline]

That means that this:

function ENT.Stuff( self ) end

is the same as

function ENT:Stuff() end

Your a life saver. Would have never figured that out.

[editline]1st December 2013[/editline]

usermessage.Hook(“informationModel”, self:getInfo) What about doing it in there? It just throws an error when doing it there.

You could do something like:

usermessage.Hook( "informationModel", function( um )
  um:ReadEntity( ):GetInfo( um )
end )

Which would expect the first entity of the message to be an instance of your sent.

The colon operator is only used for defining and calling methods. You cannot access the reference to the function through a method. However, it’s actually really simple to fix. Change your colon to a dot, however I kind of doubt that “self” is defined in the scope that you’re defining that function in. Also, why are you using usermessages? They’re outdated.

I have moved on to Data Tables to do it. Would that be best? It seems to work for the most part.

Depends what you’re trying to do.