3

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?

Randolpho
  • 55,384
  • 17
  • 145
  • 179
Jman078
  • 63
  • 3
  • can you post a copy of the error you're getting?... and, when exactly does the error occur? is it when [object listenFor:...] is run? – C4 - Travis Apr 20 '12 at 21:53
  • Well, the program isn't compiling but rather getting red flags that say: "error: use of undeclared identifier 'button1' [3] " on the lines in methodA, methodB, & methodC. – Jman078 Apr 20 '12 at 21:55
  • Are the var names button[1,2,3] declared in the .h? – CodaFi Apr 20 '12 at 21:59

1 Answers1

2

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.

C4 - Travis
  • 4,502
  • 4
  • 31
  • 56