Hi.
I'm fairly new to both Obj C and cocos2D, so I may well be making a schoolboy error here.
I have an object in my game which is basically a button. You press the button, and it lights up for 5 seconds, then turns itself off. This all works by setting the power status to 'on', and opaque-ing an overlaying sprite. It then sets a schedule with a 5 second delay which runs a method that reverses the above. There is no problem with this at all, and I can click switches until the end of time, and they will always turn off after 5 seconds.
Last night I started work on some AI. The AI calls the same function as me, and lights up the button, which does everything I expect it to. Except turn off. I've thrown a ton of NSLogs around to see what's being run, and it is definitely the right method on the right object. But it is not firing off the 5-second schedule.
In enemy.m (the AI):
- (void) hitNode:(int) target {
Actuator *myActuator = [myRail compAtIndex:0];
[myActuator powerIn];
}
and in Actuator.m (the switch):
- (void) powerIn {
[myNextNode powerIn:mainPower];
[self doGlow:150];
// This is the delay until powerdown.
[self schedule: @selector(powerDown:) interval:5.0f];
}
- (void) powerDown:(ccTime)delta {
NSLog(@"Powering Down");
[myNextNode powerOff:mainPower];
[self doGlow:0];
[self unschedule:@selector(powerDown:)];
}
Now, if it didn't work at all, I would kind of understand, but it works fine for me, and never for the AI object. I put an NSLog in the powerIn method below the scheduler line, and when the enemy activates the button, I get that log message, and so do I. But as far as I can tell, it doesn't do anything with the scheduler.
When it works, there is a method the Actuator class where, on ccTouchEnded, it calls [self powerIn], which does it's thing, and sets the scheduler.
What in the world did I do wrong? I know my AI isn't clever enough to cheat :)
I'm gonna keep hammering at this, but if anyone has any ideas, I'd appreciate it.