[Solved] setName() getname() with IF

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

[Solved] setName() getname() with IF

Post by random »

i do the following

Code: Select all

c8* myShip = "myShip";
myShip_Node->setName(myShip);
inside the class i do this

Code: Select all

        c8* myShip = "myShip";
        if (this->getName() == myShip)
        {
        std::cout << "\n YES " << " - " << this->getName();
        }
        std::cout << "\n NO " << " - " << this->getName();
inside the myClass::render

can someone tell me please why the output is
NO - myShip
NO - myShip
NO - myShip
NO - myShip
NO - myShip
NO - myShip
NO - myShip
NO - myShip
...
Last edited by random on Thu Feb 17, 2011 3:54 pm, edited 1 time in total.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

You're saying "does this pointer to a character array have the same value (point to the same location) as this other pointer to a character array?"

You need to convert one of them to a string class, then use the equals override:

Code: Select all

core::stringc myShip = "myShip";
if (myShip == this->getName())
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

Post by random »

thx a lot for the fast Answhere, it works now.
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Or - using random's approach - replace the comparison with a strcmp call.
beer->setMotivationCallback(this);
Post Reply