In the header, I declare my
NSString *name;
Variable. Then I make it a property with
@property (nonatomic,retain) NSString *name;
And I synthesize it in the implementation
@synthesize name;
And, immediately, give it a value in the init method:
name = @"HELLO";
Later I add a child to my scene. This child, later, will try to access this property. It goes like
Battle *battleScene = (Battle*)self.parent;
NSLog(@"%@",battleScene.name);
But I get “null”. Why is that?
One reason for this may be that self.parent is nil. This happens if you try to run the code in the init method of the child node.
If you do run this in the init method, move that code to the onEnter method instead: