This site requires JavaScript, please enable it in your browser!
Greenfoot back
ArchMageGaming
ArchMageGaming wrote ...

2015/12/11

variable "name" might not have been initialized error

ArchMageGaming ArchMageGaming

2015/12/11

#
Ok, so I am trying to create animation everytime the player moves the character. Here is what I have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void act()
    {
        int time;
       if(Greenfoot.isKeyDown("a")){
           move(-2);
           time = time + 1;
           if(time == 3){
               setImage("Shankmove2.jpg");
    }  
}
       if(Greenfoot.isKeyDown("d")){
           move(2);
    }
}
}
It highlights the "time = time + 1" and says variable time might not have been initialized. I am not familiar with this error so please educate me on it.
danpost danpost

2015/12/11

#
Just change line 3 to:
1
int time = 0;
so that it is initialized to its starting value.
ArchMageGaming ArchMageGaming

2015/12/11

#
oh *facepalm* I should've seen that
You need to login to post a reply.