user2121776
user2121776

Reputation: 121

Variables in a class

@interface characterclass : CCSprite
{
    bool alive;
    int speed;
    int jumpamount = 10;  <--- error
}
@property bool alive;
@property int speed;
@property int jumpamount;
@end

how do i do this like in my code, I want to have a variable in my class that equals 10.

Upvotes: 0

Views: 71

Answers (1)

J2theC
J2theC

Reputation: 4452

You need to assign these values in the initializer of your class's instances. Create an instance method called - (id)init:

- (id)init{
    self=[super init];
    if (self) {
        jumpamount=10;
    }
    return self;
}

Note that you no longer need to declare your ivars like that. @property will create an ivar for you.

Upvotes: 4

Related Questions