Help using lube
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- silver_hawk
- Prole
- Posts: 36
- Joined: Mon Feb 27, 2012 2:19 pm
Help using lube
when my client connects to my server using lube, the callback function that is called on connection, can't access the servers self.*variable_name* variables, how is the function called and why can't they access the instances local variable through self. ?
Re: Help using lube
It seems you're referencing an object from outside the object. The call back function isn't in your object, you'll have to reference it from outside.
Heres and example:
WRONG:
You're not in the scope of the obj, but rather the callback function, which itself isn't part of the obj's scope either.
RIGHT
You're still not in the scope of the object, however you're referencing variables in the scope of the object from outside of the object. You can also do this:
If you don't want to create an instance/s of the object.
Heres and example:
WRONG:
Code: Select all
obj={}
o=obj
function callback(ip,port)
self.ip=ip
self.port=port
end
RIGHT
Code: Select all
obj={}
o=obj
function callback(ip,port)
o.ip=ip
o.port=port
end
Code: Select all
obj={}
function callback(ip,port)
obj.ip=ip
obj.port=port
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Help using lube
There are no objects and no instances created, in any of your examples.tsturzl wrote:If you don't want to create an instance/s of the object.
Help us help you: attach a .love.
Who is online
Users browsing this forum: Ahrefs [Bot] and 188 guests