Hello,
I want to make a simple FSM in greenfoot with switch case.
This code doesn't work. I don't know why.
With this code, I never reach state attack2. Dont't matter how low energie is.
But: If I remove the lines
the state is changed, if the energie is lower 30.
What could be the problem?
Annotation:
getWorld().addObject(new Figur(this.energie, this.state),300,300);
does work, the new Object has the energie (also lower than 30), but the state is not changed.
public void act() {
switch (state) {
case "attack" :
if (this.energie<30) {
this.state = "attack2";
}
setRotation(getRotation()+1);
setLocation(getX()+1,getY());
if(isAtEdge()==true){
getWorld().addObject(new Figur(this.energie, this.state),300,300);
getWorld().removeObject(this);
}
break;
case "attack2":
System.out.println("state: "+ state);
break;
default:
System.out.println("default");
} if(isAtEdge()==true){
getWorld().addObject(new Figur(this.energie, this.state),300,300);
getWorld().removeObject(this);
}
