Open vhsoni opened 11 years ago
Looks that you pass incorrect context variable. Can you paste this part of your code?
In my main Activity i have written following inside onCreate method
a.setActivity(this);
a.setGLSurfaceView(mGLView);
Inside application class I have written the following:
Client.init(this, secret, null);
I am using cocos2d-2.0-x-2.0.2 with Android.
Actually all I have done is simple file copy paste. In Scoreloop.h I have declared a method:
static void SubmitScore(ScoreController* self, double result,
double minor_result = 0.0, unsigned int level = 0,
unsigned int mode = 0, std::map<std::string, std::string>* context =
NULL);
Inside jni_scoreloop.cpp, this method is defined:
void ScoreController::SubmitScore(ScoreController* self, double result, double minor_result, unsigned int level, unsigned int mode, std::map<std::string, std::string>* context)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t,
"com/ursinepaw/scoreloop/Scoreloop",
"scoreControllerSubmitScore",
"(Lcom/scoreloop/client/android/core/controller/ScoreController;DDIILjava/util/Map;)V"))
{
jdouble arg1 = result;
jdouble arg2 = minor_result;
jint arg3 = level;
jint arg4 = mode;
jobject arg5 = 0;
if (context)
{
jclass mapClass = t.env->FindClass("java/util/HashMap");
if (mapClass)
{
jsize map_size = context->size();
jmethodID init = t.env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hash_map = t.env->NewObject(mapClass, init, map_size);
jmethodID put = t.env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
for (std::map<std::string, std::string>::const_iterator it = context->begin(); it != context->end(); ++it)
{
jstring key = t.env->NewStringUTF(it->first.c_str());
jstring value = t.env->NewStringUTF(it->second.c_str());
t.env->CallObjectMethod(hash_map, put, key, value);
t.env->DeleteLocalRef(value);
t.env->DeleteLocalRef(key);
}
arg5 = hash_map;
t.env->DeleteLocalRef(mapClass);
}
}
t.env->CallStaticVoidMethod(t.classID, t.methodID, (jobject)self, arg1, arg2, arg3, arg4, arg5);
if (arg5)
t.env->DeleteLocalRef(arg5);
t.env->DeleteLocalRef(t.classID);
}
}
Eclipse shows error both on the declaration and definition lines.
Try to add #include <string>
to Scoreloop.h
I have added #include
Now Im getting error on below line of ScoresController::SetSearchCriteria method.
CC_ASSERT(strlen(method_name) > 0);
Add to .cpp file #include <string.h>
I added #include <string.h>
include in jni_scoreloop.cpp
file but it didn't work. Getting same issue at CC_ASSERT
method. While I am hovering mouse over CC_ASSERT method it points me towards following issue. 'CCMessageBox' was not declared in this scope
.
Please, be ensured that all cocos2dx files nessesary files included correctly. CCMessageBox
must be visible by compiler, and CC_ASSERT too.
Actually I am new to C++ and Cocos2dx. Can you provide the basic sample code which help me submit score, get the leaderboard etc?
I have added all necessary includes in this project, for cocos2dx I have included using namespace cocos2d;
. I am able to access all classes of Cocos2dx.
Hi, I downloaded upSL-master.zip file.
In Scorloop.h file while declaring following line:
static void SubmitScore(ScoreController* self, double result, double minor_result = 0.0, unsigned int level = 0, unsigned int mode = 0, std::map* context = NULL);
It shows the following errors
Multiple markers at this line
And also in the jni_scoreloop.cpp file where this method is defined shows the following error
prototype for 'void Scoreloop::ScoreController::SubmitScore(Scoreloop::ScoreController_, double, double, unsigned int, unsigned int, std::mapstd::basic_string<char, std::basicstring >)' does not match any in class 'Scoreloop::ScoreController'
what can be the problem?