Need help with CCHttpRequest and httpresponse_selector

Hi

I´m new to cocos2dx and programming cpp in general, so please bear with me :stuck_out_tongue:

Trying to make a simple level design tool for my game level designer using XML. The plan is to make him edit a XML file that is on a server, setting game properties etc. The game should read this XML file at startup and set its properties accordingly.
If anyone has other approaches for making such a tool I would very much appreciate suggestions.

Found this guide: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_CCHttpClient

Having problems setting the response callback function, xcode says : "No matching member function for call to ‘setResponseCallback’

Using cocos2d-x-2.1.4, developing for ios and Android

void LevelData::getData()
{
    cocos2d::extension::CCHttpRequest* request = new cocos2d::extension::CCHttpRequest();
    request->setUrl("https://some-url-/properties.plist");
    request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet);
    request->setResponseCallback(this, httpresponse_selector(LevelData::onHttpRequestCompleted));


}

void LevelData::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data)
{
    //handle request here
}

Edit: I was able to read files using cURL

void LevelData::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data)
It’s wrong method signature, jump to httpresponse_selector definition and you’ll see that correct signature is:
void LevelData::onHttpRequestCompleted(HttpClient* client, HttpResponse* response);

Thank you Sergey. Unfortunately the problem is still there - I must be overlooking something. I checked out the example code in TestCpp/Classes/ExtensionsTest/NetworkTest and compared it with my header files and cpp files… but still xcode complains: "No matching member function for call to ‘setResponseCallback’

void LevelData::getData()
{
    cocos2d::extension::CCHttpRequest* request = new cocos2d::extension::CCHttpRequest();
    request->setUrl("http://asbjorn.nedrehagen.net/GoodPuppy/properties.plist");
    request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet);
    request->setResponseCallback(this, httpresponse_selector(LevelData::onHttpRequestCompleted));

}

void onHttpRequestCompleted(cocos2d::extension::CCHttpClient *sender, cocos2d::extension::CCHttpResponse *response)
{

    //handle response

is httpresponse_selector a new thing? I’m on 2.0.4 and I’m using callfuncND selector and it works

Found the error: the class was not inheriting from CCLayer. I´m able to read the file from the webserver, but I get a runtime error when releasing the request object:

Cocos2d: Assert failed: reference count should greater than 0
Assertion failed: (m_uReference > 0), function release, file /

void LevelData::getData()
{
    cocos2d::extension::CCHttpRequest* request = new cocos2d::extension::CCHttpRequest();
    request->setUrl("http://some-url/properties.plist");
    request->setRequestType(cocos2d::extension::CCHttpRequest::kHttpGet);
    request->setResponseCallback(this, httpresponse_selector(LevelData::onHttpRequestCompleted));
    request->setTag("GET test1");
    CCHttpClient::getInstance()->send(request);
    request->release(); //This causes the runtime error
}

Justin Godesky wrote:

is httpresponse_selector a new thing? I’m on 2.0.4 and I’m using callfuncND selector and it works
Yes, I believe it is.
Reference says: DEPRECATED_ATTRIBUTE void setResponseCallback ( CCObject * pTarget,
SEL_CallFuncND pSelector
)

what was the problem herE?