Problem with Basic iPhone Math

Discussion in 'iOS Programming' started by hackmods, Feb 13, 2010.

  1. hackmods macrumors newbie

    Joined:
    Feb 8, 2010
    #1
    Hey guys,

    I wrote a basic who's that pokemon app today and im trying to add scores and lives.

    First for lives I diclare this near the begining of my .m file

    Code:
    
    #import "Who_s_That_Pokemon_ViewController.h"
    
    @implementation Who_s_That_Pokemon_ViewController
    
    int	health = 4;
    
    when a wrong pokemon name is picked it runs this method

    Code:
    -(void) calcHealth {
    	if (health == 1)
    	{
    		ball3.hidden= NO;
    	}
    	else if (health == 2)
    	{
    		ball1.hidden = YES;
    		health = health - 1;
    	}
    	else if (health == 3)
    	{
    		ball2.hidden == YES;
    		health = health - 1;
    	}
    	else if (health == 4)
    	{
    		ball3.hidden = YES;
    		health = health - 1;
    	}
    }
    the ball variable refer to pictures, it hides the 3 pokeballs to show you missed 3 pokemon. When it runs the first time it works fine. but after the first time it skips to health ==1 for some reason.

    any insight?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Your declaration of health seems misplaced. Either make it an instance variable or make it a static, depending on your needs.
     

Share This Page