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

2018/3/17

He can touch, when he has score > 5.

Findr Findr

2018/3/17

#
Hi, how I can make, when actor score is more than 5, he can collect Tulipan.
if(score == 5)
{
if(isTouching(Tulipan.class))
        {
            this.setLocation (1500,1000);
            this.getWorld().removeObject(this.getOneIntersectingObject(Tulipan.class));
        }
}
Super_Hippo Super_Hippo

2018/3/17

#
I am not exactly sure what you try to do (or what the shown is doing what it shouldn't) but the title says greater than 5 and in your code the conditions says that score has to be 5.
Yehuda Yehuda

2018/3/19

#
The following code (in a compressed version) should do what you asked:
if (score > 5 && isTouching(Tulipan.class)) {
    setLocation(1500, 1000);
    removeTouching(Tulipan.class);
}
Findr Findr

2018/3/20

#
It´s not working. I want, when actor has score 5 or more than 5, he can collect Tulipan. Here is my code in Counter actor.
int score = 0;
    {
public void act() 
    {
        setImage(new GreenfootImage("SEBRANÝCH KYTEK: 10/" +score, 24, Color.BLACK, Color.WHITE));
        
    }    

    public void addScore()
    {
        score++;
    }
danpost danpost

2018/3/20

#
The code provided by Yehuda should work. To allow when score is at 5, just change '>' to '>='. You only need to set the image of the Counter object initially and when the score changes:
public int score;

public Counter()
{
    updateImage();
}

private void updateImage()
{
    setImage(new GreenfootImage("SEBRANÝCH KYTEK: 10/" +score, 24, Color.BLACK, Color.WHITE));
}

public void addScore()
{
    score++;
    updateImage();
}
Yehuda Yehuda

2018/3/21

#
I wasn't sure which one to do, so I went according to the title and figured if there is a problem it will be mentioned, I didn't want to assume this information wasn't known.
You need to login to post a reply.