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

2015/4/26

problems with this pls help me :D

Yurey Yurey

2015/4/26

#
hi can u help me out there:
private void atEdge()
    {
        if (atWorldEdge())
        {
            removeObject(this);
        }
i doesnt work with "this" i think but i dont know how to paraphrase it ^^ here is the atWorldEdge boolean:
 public boolean atWorldEdge()
    {
        if(getX() <=1 || getX() > getWorld().getWidth())
            return true;
        if(getY()<= 1 || getY() > getWorld().getHeight())
            return true;
        else
            return false;
    }
azazeel azazeel

2015/4/26

#
how about this : getWorld().removeObject(this); itsn't about "this", it's bcoz removeobject method is belong to world class
azazeel azazeel

2015/4/26

#
oh anyway, next time try to put the compile error warning
Yurey Yurey

2015/4/26

#
thank u :D 1 more question is something wrong with my boolean ? because the fireball isnt removed :/
danpost danpost

2015/4/26

#
Yurey wrote...
thank u :D 1 more question is something wrong with my boolean ? because the fireball isnt removed :/
Yes. The high edge of the world dimensions can not be passed in a bounded world (or even reached, since zero is the first value and the dimension minus one is the last.).
Yurey Yurey

2015/4/26

#
ok what i need 2 change ?
Yurey Yurey

2015/4/26

#
ohh sorry *to not 2
danpost danpost

2015/4/26

#
Yurey wrote...
ok what i need 2 change ?
The second conditions in both lines 3 and 5.
Yurey Yurey

2015/4/26

#
ty danpost now it works but the lower site buggs i think the Fireball wont get removed pls check my script
public boolean atWorldEdge()
    {
        if(getX() <=2 || getX() > 58)
            return true;
        if(getY() <=2 || getY() > 78)
            return true;
        else
            return false;
    }
    public void act() 
    {
        // Add your action code here.
        move(1);
        atEdge();
    } 
    private void atEdge()
    {
        if (atWorldEdge()==true)
        {
            getWorld().removeObject(this);
        }
    }
danpost danpost

2015/4/26

#
I see no issues with the code given.
You need to login to post a reply.