Help using lube

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
silver_hawk
Prole
Posts: 36
Joined: Mon Feb 27, 2012 2:19 pm

Help using lube

Post by silver_hawk »

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. ?
User avatar
tsturzl
Party member
Posts: 161
Joined: Fri Apr 08, 2011 3:24 am

Re: Help using lube

Post by tsturzl »

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:

Code: Select all

obj={}
o=obj
function callback(ip,port)
    self.ip=ip
    self.port=port
end
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

Code: Select all

obj={}
o=obj
function callback(ip,port)
   o.ip=ip
   o.port=port
end
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:

Code: Select all

obj={}
function callback(ip,port)
   obj.ip=ip
   obj.port=port
end
If you don't want to create an instance/s of the object.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Help using lube

Post by Robin »

tsturzl wrote:If you don't want to create an instance/s of the object.
There are no objects and no instances created, in any of your examples.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 188 guests