getName() doesn't work

In my HelloWorld::init() function, I set the pawn’s name, then right after that, when I try to print that pawn’s name it comes out as random letter followed by a question mark. Why does this happen?

PAWN->setName("Player");
CCLOG("%s", PAWN->getName());

This outputs “{?” or something like that.

Because you try to output std::string object but CCLOG requires char* string.
Call c_str to get it:

CCLOG("%s", PAWN->getName().c_str());
1 Like