Paul Guymer
Paul Guymer

Reputation: 5

variable not assignable missing__block

Im trying to add a 10 count loop to my game but when i run the code it generates a "variable not assignable missing__block" error message. Can anyone tell me where i'm going wrong and point me in the right direction?

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
    CGPoint currentLocation = [[touches anyObject] locationInNode:self];
    CGPoint previousLocation = [[touches anyObject] previousLocationInNode:self];
    CGRect shipRect = _ship.frame;
    if (CGRectContainsPoint(shipRect, previousLocation))
    {
       [self launch:10 p1:currentLocation p2:previousLocation rect1:shipRect];
    }
 }

-(void)launch:(int)count p1:(CGPoint) currentLocation p2:(CGPoint) previousLocation rect1:(CGRect) shipRect
{
    CGPoint lvPosition = CGPointMake(_ship.position.x - (previousLocation.x - currentLocation.x), _ship.position.y);
_ship.position = lvPosition;

    SKAction *sound = [SKAction playSoundFileNamed:@"slideup.mp3" waitForCompletion:NO];
    SKAction *moveNode = [SKAction moveByX:lvPosition.x y:10.0 duration:3.0];

   [_ship runAction: sound];
   [_ship runAction: moveNode completion:^{[self launch:count-- p1:currentLocation p2:previousLocation rect1:shipRect];}]; /*variable not assignable missing__block error*/

}

Upvotes: 0

Views: 369

Answers (2)

newacct
newacct

Reputation: 122429

Non-__block local variables are not assignable in blocks.

However, making it __block is probably not what you want either. The method name runAction:completion: sounds like it will call the "completion" block once, after the action finishes. Since it is called once, and count is not used thereafter, post-decrementing it is pointless.

Upvotes: 1

Jonathan Cichon
Jonathan Cichon

Reputation: 4406

i think you are trying to decrement the variable count which is not defined as __block. You have to declare each variable you want to change inside a block with __block, for example __block int count;

[EDIT] in your case the simplest solution is to asign count-1 to the recursive call, as you do not need the result of count-- later on

Upvotes: 1

Related Questions