Question

I'm very new to programming in general. I am trying to update the UILabel "Lives" with the integer life. However I keep getting the warning "expression result unused" in the line

Lives.text = @"",life;

//
//  Game.m
//  SprinklerDash

#import "Game.h"

@interface Game ()

@end

@implementation Game


-(void)Walk{
    Runner.animationImages = [NSArray arrayWithObjects:
                              [UIImage imageNamed:@"Runner1.png"],
                              [UIImage imageNamed:@"Runner2.png"],
                              [UIImage imageNamed:@"Runner3.png"],
                              [UIImage imageNamed:@"Runner4.png"],
                              [UIImage imageNamed:@"Runner5.png"],
                              [UIImage imageNamed:@"Runner6.png"],
                              [UIImage imageNamed:@"Runner7.png"],
                              [UIImage imageNamed:@"Runner8.png"], nil];

    [Runner setAnimationRepeatCount:INFINITY];
    Runner.animationDuration = .75;
    [Runner startAnimating];
}

-(void)Moving{
    Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
    if(CGRectIntersectsRect(Runner.frame, Water.frame)){
        life = life - 1;
        Lives.text = @"",life;
        Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);

    }
}

-(IBAction)StartGame:(id)sender{
    Start.hidden=YES;
    UpMovement = 3;
    [self Walk];
    Movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(Moving) userInfo:nil repeats:YES];
}




- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Was it helpful?

Solution

If Lives is your label, Then it should be as below.

Lives.text =[NSString stringWithFormat:@"%@",life]; /// if life is string  
Lives.text =[NSString stringWithFormat:@"%d", life]; /// if life is integer

OTHER TIPS

Replace this with your Method, and it is good to go.

-(void)Moving{
    Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
    if(CGRectIntersectsRect(Runner.frame, Water.frame)){
        life = life - 1;
        lives.text = [NSString stringWithFormat:@"%d",life];
      //  Lives.text = @"",life;
        Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);

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