Question

I’m making a program in C4 that consists of three separate buttons that change both their shape when pressed. When I create a bunch of methods for each button like this:

@implementation MyButton

-(void)methodA {
    C4Log(@"methodA");
    [button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];
}

-(void)methodB {
    C4Log(@"methodB");
    [button2 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, centerPos.y - buttonHeight/2.0f, buttonWidth, buttonHeight)];
}

-(void)methodC{
    C4Log(@"methodC");
    [button3 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, canvasHeight - 280, buttonWidth, buttonHeight)];
}

@end

...and then call for them in the canvas...

[button1 listenFor:@"touchesBegan" fromObject:button1 andRunMethod:@"methodA"];
[button2 listenFor:@"touchesBegan" fromObject:button2 andRunMethod:@"methodB"];
[button3 listenFor:@"touchesBegan" fromObject:button3 andRunMethod:@"methodC"];

...All I end up getting are a bunch of undeclared identifier errors. What am I doing wrong?

Was it helpful?

Solution

I'd need to see a copy of the variables you've defined in the MyButton.h file to be sure, but as far as I can tell from your error and your code the following line is calling ivars:

[button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];

The ivars centerPos, buttonWidth and buttonHeight need to be defined in your .h file, if one of them isn't being declared there then you will run into this kind of error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top