EventListenerDelegate Context

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

Kyuur
Posts: 1
Joined: 01 Oct 2014, 05:14

EventListenerDelegate Context

Postby Kyuur » 03 Dec 2014, 20:53

Hi folks!

I was wondering if anyone can provide an explanation on the purpose of the context argument when creating an EventListenerDelegate for an Event Listener. The examples typically use (unsigned long long)this as the value, however that does not work when calling from something like main(). I subbed in the number 0 instead of this and the callback seemed to function correctly. Is there any need to have a valid value for this argument if you don't need a reference to the calling class?
MBagnati
Posts: 126
Joined: 12 Feb 2013, 10:57

Re: EventListenerDelegate Context

Postby MBagnati » 04 Dec 2014, 23:51

The context argument is an optional value.
SmartFox API does not use it; simply propagates it
The argument has been designed to carry an information into the event listener.
This "opaque" argument provides a way (if developer has this need) to move a value into event listener.
The context argument is a number, so the developer can store a numeric value or a pointer to an object instance.
When the developer has not any information to propagate at the event listener, he can set the context argument with a meaningless value: for instance 0.

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 24 guests