user1892541
user1892541

Reputation: 35

"unused variable"

@implementation demoScene{

-(void) initializeScene {
moon *_moon=[[moon alloc]init];
}
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {

    deltaTime =deltaTime+visitor.deltaTime;
    NSLog(@"delta time=%0.12f",deltaTime);
    [_moon print:deltaTime/100000];
}
@end

Here is my problem.

I want to create an object from moon class in initializeScene method and I want to send message to that object in updateBeforeTransform method.

When I type the code like this, I can not send message to _moon object and get "unused variable" warning message.

I know the object is out of scope but if i need to send message from updateBeforeTransform method. And updateBeforeTransform method is called like 60 time in a second. So I did not want to create an object 60 times in a seconds.

Any suggestion would be appreciated.

Upvotes: 1

Views: 290

Answers (1)

rmaddy
rmaddy

Reputation: 318774

You need an instance variable instead of creating a new variable in the initializeScene method:

@implementation demoScene {
    moon *_moon; // You may already have this in the .h file - just have it in 1 place.
}

- (void)initializeScene {
    _moon = [[moon alloc] init]; // assign to ivar
}

- (void)updateBeforeTransform:(CC3NodeUpdatingVisitor*) visitor {
    deltaTime = deltaTime + visitor.deltaTime;
    NSLog(@"delta time=%0.12f", deltaTime);
    [_moon print:deltaTime / 100000];
}

@end

Side note - Class names should begin with uppercase letters. Variables and method names begin with lowercase letters.

Upvotes: 2

Related Questions