I know xcode doesn't retain an int, but my code won't seem to update the number at all from a function.
I have in GameController.h
int charMainTouch;
and
@property (assign) int charMainTouch;
and in GameController.m:
-(void)awakeFromNib {
charMainTouch=1;
NSLog(@"%d",charMainTouch);
}
this stores charMainTouch as 1 ok. But, when I call a function from another class it won't store the int
in GameController.m:
-(void) mainChar_touch:(int)touchTrue{ // when an class/object in touched
charMainTouch = touchTrue;//this is=2
NSLog(@"%d",charMainTouch);//this prints out 2
}
-(void) update:(CADisplayLink*)sender {
NSLog(@"%d",charMainTouch);//this still outputs 1 as if the "-(void) mainChar_touch:(int)touchTrue" had no effect on storing the int!
}
-(void)startGame {//this was already called
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@ selector(update:)];
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
I don't know why it won't update the int from this function! I have tried this:
-(void) update:(CADisplayLink*)sender {
charMainTouch = charMainTouch+1;
NSLog(@"%d",charMainTouch);//works! prints out an increasing number
}
but when the "-(void) mainChar_touch:(int)touchTrue" is called at any point, it doesn't effect the int at all...! Any ideas why?
The function, altho called from outside is still within the class so shouldn't it update the int? I've tried everything.
It seems you're creating a totally new game controller in your touchesBegan:withEvent: method.
And then you're setting a property on the new game controller instance, not the instance you may have had already.