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

2014/5/29

Boolean Statement

SullyFish SullyFish

2014/5/29

#
so Im having problems turning my "touched" statement true I dont know where I should put it, wherever I put it it says it cant be boolean and its odd anyways I was wondering if someone could turn it true when he makes contact with actor ninja heres all the coding in the "good" class which stands for good barrel
public class good extends barrels
{
    public boolean touched;
    private int life = 25;
    private GreenfootImage explode = new GreenfootImage("explode.png");
    public void act() 
    {
       Healup();
         if(life <= 0) {
            getWorld().removeObject(this);
        {
        
    if(isTouched);
        life--;
    }
 
    }
    }
    public void Healup()
    {
        Ninja ninja = (Ninja) getOneIntersectingObject(Ninja.class);
        if (ninja != null){
            
            Floor bg = (Floor) getWorld();
            bg.bar.add(5);
            setImage(explode);
            getImage();
            
            bg.goodbarrel--;
        }
    }
        public boolean isTouched()
        {
            return touched;
    }
   }
        
    

please and thank you!
elias.groll elias.groll

2014/5/29

#
Please explain ur code :) If u want to check if an object isTouching any other object u can use the isTouching() function with parameter null. But i dont know if it is what u need.
SullyFish SullyFish

2014/6/2

#
after the barrel is touched, the barrel starts losing its life(for it to despawn) so I want the actor to touch the barrel and then so the barrel can start counting down no matter where the other actor is.
SullyFish SullyFish

2014/6/5

#
hello?
danpost danpost

2014/6/5

#
Line 13 uses 'isTouched' as a condition (as if it was a boolean field). You must follow it with an empty set of parenthesis to call the 'isTouched' method which returns a boolean value (or just change it to 'touched' to get the boolean value directly).
You need to login to post a reply.