Mutable global methods?

34 views Asked by At

I am trying to use a block of code in multiple buttons, but there are four integer values that change in each of the buttons that I use it in. Can anybody help?

Here is a simplified part of my code which I get either Sigbart Thread error or it will not run at all. (I only need help with using the block, I have proper syntax in the rest of the code)

//.h file

@interface

@property BOOL playerTurn;
@property (weak, nonatomic) IBOutlet UILabel *firstPlayer;
@property (weak, nonatomic) IBOutlet UILabel *playerOneScore;
@property (weak, nonatomic) IBOutlet UILabel *playerTwoScore;
@property (weak, nonatomic) IBOutlet UITextField *playerTwoName;
@property (weak, nonatomic) IBOutlet UITextField *playerOneName;
@property (weak, nonatomic) IBOutlet UIButton *myButton00;
@property (weak, nonatomic) IBOutlet UIButton *myButton01;

- (IBAction)button00:(UIButton *)sender;
- (IBAction)button01:(UIButton *)sender;
- (void)pieceChanger;

//.m file

@implementation

- (void)pieceChanger
{
    NSArray *myButtons;
    myButtons = [NSArray arrayWithObjects: _myButton00, _myButton01,_myButton02,_myButton03,_myButton04,_myButton05,_myButton06,_myButton07,_myButton10,_myButton11,_myButton12,_myButton13,_myButton14,_myButton15,_myButton16,_myButton17,_myButton20, _myButton21,_myButton22,_myButton23,_myButton24,_myButton25,_myButton26,_myButton27,_myButton30,_myButton31,_myButton32,_myButton33,_myButton34,_myButton35,_myButton36,_myButton37,_myButton40,_myButton41,_myButton42,_myButton43,_myButton44,_myButton45,_myButton46,_myButton47,_myButton50,_myButton51,_myButton52,_myButton53,_myButton54,_myButton55,_myButton56,_myButton57,_myButton60,_myButton61,_myButton62,_myButton63,_myButton64,_myButton65,_myButton66,_myButton67,_myButton70,_myButton71,_myButton72,_myButton73,_myButton74, _myButton75,_myButton76,_myButton77,nil];

    int x;
    int rowMax;
    int rowMin;
    int diagMax;
    int diagMin;

    if(_playerTurn)
    {
        _myButton33.backgroundColor = [UIColor blackColor];

        _myButton33.tag = 1;

        for(int y = x; ((UIButton*)[myButtons objectAtIndex:y]).tag != 1 || y >= 0; y - 8)
        {
            if(((UIButton*)[myButtons objectAtIndex:y]).tag == 1)
            {
                for(int z = y; z <= x; z + 8)
                {
                    ((UIButton*)[myButtons objectAtIndex:z]).tag = 1;
                    ((UIButton*)[myButtons objectAtIndex:z]).backgroundColor = [UIColor blackColor];
                }
            }

        }(Continued)

- (IBAction)button00:(UIButton *)sender
{
    int x = 0;
    int rowMax = 7;
    int rowMin = 0;
    int diagMax = 0;
    int diagMin = 0;
    [button00.pieceChanger];
}

^this is what I am trying to get, but I cannot get the right syntax.

Thanks!

0

There are 0 answers