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

2020/12/15

Static int won't decrease.

ItzLukeStorm ItzLukeStorm

2020/12/15

#
I have whenever objects hit a certain object, they get objects hitting the object get removed and a static int is changed, but it only changes with FireBall.class. Please help.
import greenfoot.*; 

public class Center extends Actor
{
    public void act() 
    {
        touchStuff();
    }  
    
    public void touchStuff()
    {
        if(isTouching(Phantom.class))
        {
            MyWorld.health = MyWorld.health - 1;
            removeTouching(Phantom.class);
        }
        if(isTouching(Spider.class))
        {
            MyWorld.health = MyWorld.health - 1;
            removeTouching(Spider.class);
        }
        if(isTouching(FireBall.class))
        {
            MyWorld.health = MyWorld.health - 1;
            removeTouching(FireBall.class);
        }
        if(isTouching(Vex.class))
        {
            MyWorld.health = MyWorld.health - 1;
            removeTouching(Vex.class);
        }
    }
}
Roshan123 Roshan123

2020/12/16

#
Remove static....(only write int) Hope it helps u
Roshan123 Roshan123

2020/12/16

#
Static is used to share 1 particular same value over certain classes Example:- static int ur_health=50 And now if u share the health in other classes then It will share same health for all the classes
ItzLukeStorm ItzLukeStorm

2020/12/16

#
Thank you so much
Roshan123 Roshan123

2020/12/16

#
Welcome!!!!
You need to login to post a reply.