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

2021/3/9

Change variable from another actor

Plane_Crazy Plane_Crazy

2021/3/9

#
I am trying to figure out how to change a variable in another actor so I can calculate the number of "explosions" there are.
Plane_Crazy Plane_Crazy

2021/3/9

#
Main code: public class Binary extends Actor { public static int explode = 0; /** * Act - do whatever the Binary wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(explode >= 3) { Greenfoot.stop(); } } } Code in one actor public void act() { // if (getY() < getWorld().getHeight() - 80) { setLocation(getX(), getY() + 2); } else { setImage("Mushroom.png"); explode=explode+1; } Code in second actor public void act() { // if (getY() < getWorld().getHeight() - 80) { setLocation(getX(), getY() + 2); } else { setImage("Mushroom.png"); explode=explode+1; } When both of these add up to 3, I want the game to end. I am not sure how to do that though.
danpost danpost

2021/3/9

#
For:
explode = explode+1;
in second actor, use:
Binary.explode++;
Plane_Crazy Plane_Crazy

2021/3/9

#
Okay, I added it but the game still does not end. I am not sure if the variable is updating or not.
danpost danpost

2021/3/10

#
danpost wrote...
in second actor, use:
Binary.explode++;
In first actor, also.
Plane_Crazy Plane_Crazy

2021/3/10

#
I did that. But the game still does not end.
danpost danpost

2021/3/10

#
Plane_Crazy wrote...
I did that. But the game still does not end.
How many of those actors (first and second) are placed in the world?
Plane_Crazy Plane_Crazy

2021/3/12

#
several. I think that there is around 10
danpost danpost

2021/3/12

#
Plane_Crazy wrote...
several. I think that there is around 10
Do you get multiple mushrooms from them?
You need to login to post a reply.