Weird bug with setTag()

Following are two similar sets of code with the newObject~~>setTag placed at 2 different positions:
Code A:
@ newObject = CCSprite::create~~ IDCOCONUT]);
newObject~~>setPosition + 1) * 80 + 24, 60) );
Bar_Panel~~>addChild(newObject, 0, 10);
invItems~~>addObject;
newObject~~>setTag(objID~~>getTag);
CCLog, objID~~>getTag());@

Code B:

@ newObject = CCSprite::create(fName[objID~~>getTag~~ IDCOCONUT]);
newObject~~>setTag);
newObject~~>setPosition( ccp((invItems~~>count + 1) * 80 + 24, 60) );
Bar_Panel~~>addChild(newObject, 0, 10);
invItems~~>addObject;
CCLog, objID~~>getTag());@

objID, Bar_Panel is of type CCSprite
invItems is of type CCArray

Code A runs fine and the log shows:
tag in addTOInv function : 113 113

but Code B always shows 10 as the tag of newObject
tag in addTOInv function : 10 113

Should there be any restrictions on when the tag can be set (probably like only after the position has been set or anything like that) ?

The magic happens on Bar_Panel > addChild;*
On that line, the third argument is the TAG of the object you are trying to add.
In case A, you are setting the tag of newObject to *objID
> getTag* AFTER adding it to Bar_Panel and setting the tag to 10. So when you print the Tag, you get
objID > getTag**.
In case B, you are setting the tag of**newObject* to *objID
> getTag()* BEFORE adding it to Bar_Panel and setting the tag to 10. So when you print the Tag, you get 10 instead of *objID -> getTag()*

aaww… somehow it never crossed my mind… ! thx for pointing it out :slight_smile: