[Solved] Can't catch Chartboost events

Hello, I’m trying to catch Chartboost events, but nothing happens. Here is my code :

MyClass.h

#include "cocos2d.h"
#include "PluginChartboost/PluginChartboost.h"

USING_NS_CC;

class MyClass : public sdkbox::ChartboostListener
{
public:

void onChartboostCached(const std::string& name);
bool onChartboostShouldDisplay(const std::string& name);
void onChartboostDisplay(const std::string& name);
void onChartboostDismiss(const std::string& name);
void onChartboostClose(const std::string& name);
void onChartboostClick(const std::string& name);
void onChartboostReward(const std::string& name, int reward);
void onChartboostPauseClickForConfirmation();
};

MyClass.cpp

void MyClass::onChartboostCached(const std::string& name) {
    CCLOG("event");
}
bool MyClass::onChartboostShouldDisplay(const std::string& name) {
    CCLOG("event");
    return true;
}
void MyClass::onChartboostDisplay(const std::string& name) {
    CCLOG("event");
}
// and so on...

HelloWorld.cpp

MyClass *myClass;
sdkbox::PluginChartboost::setListener(myClass);

sdkbox::PluginChartboost::show("Level Complete");

What I’am doing wrong ? Thanks for your help.

I don’t see where you are calling:

sdkbox::PluginChartboost::init();

I call sdkbox::PluginChartboost::init(); in AppDelegate.cpp

in your HelloWorld.cpp, try a simple test. Extend sdkbox::ChartboostListener and add in the callbacks and their functions and just try to make HelloWorld catch the events first and get it working properly.

HelloWorld.h

#include "cocos2d.h"
#include "PluginChartboost/PluginChartboost.h"

USING_NS_CC;

class HelloWorld : public sdkbox::ChartboostListener
{
public:

void onChartboostCached(const std::string& name);
bool onChartboostShouldDisplay(const std::string& name);
void onChartboostDisplay(const std::string& name);
void onChartboostDismiss(const std::string& name);
void onChartboostClose(const std::string& name);
void onChartboostClick(const std::string& name);
void onChartboostReward(const std::string& name, int reward);
void onChartboostPauseClickForConfirmation();
};

HelloWorld.cpp

sdkbox::PluginChartboost::init();
sdkbox::PluginChartboost::setListener(this);

//
void HelloWorld::onChartboostCached(const std::string& name) {
    CCLOG("event");
}
bool HelloWorld::onChartboostShouldDisplay(const std::string& name) {
    CCLOG("event");
    return true;
}
void HelloWorld::onChartboostDisplay(const std::string& name) {
    CCLOG("event");
}
// and so on...

Also, can you actually show an ad? sdkbox::PluginChartboost::show(sdkbox::CB_Location_Default);

And you setup a Chartboost account, edited sdkbox_config.json, etc too?

When I’am trying to extend sdkbox::ChartboostListener in HelloWorld.cpp :

class HelloWorld: public cocos2d::LayerColor, public sdkbox::ChartboostListener

I’am getting an error “Allocating an object of abstract class type HelloWorld” at :

CREATE_FUNC(HelloWorld)  

Yes, I can show an ad and Chartboost account is setuped;

So this is what we are using in our sample’s that we test with I removed a few function definitions that I know you don’t need. We extend Layer and not LayerColor, honestly I have not used LayerColor in more than a year, I think.

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "PluginChartboost/PluginChartboost.h"

class HelloWorld : public cocos2d::Layer, sdkbox::ChartboostListener
{
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();

    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
 
    //Ad callbacks
    void onChartboostCached(const std::string& name);
    bool onChartboostShouldDisplay(const std::string& name);
    void onChartboostDisplay(const std::string& name);
    void onChartboostDismiss(const std::string& name);
    void onChartboostClose(const std::string& name);
    void onChartboostClick(const std::string& name);
    void onChartboostReward(const std::string& name, int reward);
    void onChartboostFailedToLoad(const std::string& name, sdkbox::CB_LoadError e);
    void onChartboostFailToRecordClick(const std::string& name, sdkbox::CB_ClickError e);
    
    //Miscellaneous callbacks
    void onChartboostConfirmation();
    void onChartboostCompleteStore();
};

#endif // __HELLOWORLD_SCENE_H__

Thank you very much, now everything works fine.

MyClass *myClass = new MyClass();