Selectors

Hi,

I am still trying to learn cocos2dx and it seems that while programming, i use alot of different selectors in my codes.

So there is like
menu_selector
schedule_selector
callfunc_selector
event_selector

Rather than following tutorials blindly, i wish that someone can clarify all these selectors for me.
Thx! =>

Jordan Lim wrote:

Hi,
>
I am still trying to learn cocos2dx and it seems that while programming, i use alot of different selectors in my codes.
>
So there is like
menu_selector
schedule_selector
callfunc_selector
event_selector
>
Rather than following tutorials blindly, i wish that someone can clarify all these selectors for me.
Thx! =>
In Objective-C, you can use single type SEL and @selector() (on errors, application will crash or throw exception).

C++ have more robust type checks, so each *_selector types declares which arguments such method should have. You can look at exact declarations in CCObject.h, for example, SEL_CallFuncO declared as:
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
In this case, you should pass method that accepts 1 argument of type CCObject**, and returns nothing.
void RaceScene::parseDictionary(CCObject *dicObject);
CCCallFuncO *func = CCCallFuncO::create(callfuncO_selector(RaceScene::parseDictionary), dic);
Of course, “dic” has type CCDictionary *, it will be casted to CCObject *, and you should manually cast it back to CCDictionary** inside parseDictionary.

Hi, Jordan!

You can simple see, what each selector means. In CCObject.h:

typedef void (CCObject::SEL_SCHEDULE);
typedef void ;
typedef void ;
typedef void ;
typedef void ;
typedef void ;
typedef void ;
typedef int ;
#define schedule_selector
#define callfunc_selector
#define callfuncN_selector
#define callfuncND_selector
#define callfuncO_selector
#define menu_selector
#define event_selector
#define compare_selector
So, schedule_selector - pointer to the function, that takes 1 float argument.
menu_selector - pointer to the function, that takes 1 CCObject
argument.

And so on.