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

2020/4/14

I want to write a method that detects if a particle is falling.

Atharva1912 Atharva1912

2020/4/14

#
isFalling() Returns a boolean value indicating whether this particle is in free-fall or not. A particle is falling if it is above the maximum y value and there is nothing in the space immediately underneath it. Be sure not to access the world out of bounds (you cannot fall outside the world).
 public boolean isFalling()
    {
        if (this.getWorld() != null)
        {
            return (this.getGridY() < 
                this.getWorld().getHeight() - 1
                && this.getWorld().getOneObjectAtOffset(this.getGridX(),
                    this.getGridY() + 1, Particle.class == null));
        }
        return false; 
    }
I have written the above code, but It's showing an error saying "Cannot find Symbol - method getOneAtObjectAtOffset(int, int, boolean)
danpost danpost

2020/4/14

#
Move exactly one parenthesis around to the other side of " == null".
Atharva1912 Atharva1912

2020/4/14

#
I might be really dumb, But I could not figure out what exactly I need to do. Sorry
danpost danpost

2020/4/14

#
Atharva1912 wrote...
I might be really dumb, But I could not figure out what exactly I need to do. Sorry
There is only one place in the given code where " == null" occurs and looking at both sides, only one has parenthesis. Take the closest one and move it to the other side of " == null".
Atharva1912 Atharva1912

2020/4/14

#
danpost wrote...
Atharva1912 wrote...
I might be really dumb, But I could not figure out what exactly I need to do. Sorry
There is only one place in the given code where " == null" occurs and looking at both sides, only one has parenthesis. Take the closest one and move it to the other side of " == null".
Hey, I tried doing as you suggested, but it still shows the same error.
danpost danpost

2020/4/14

#
Show your updated method.
Atharva1912 Atharva1912

2020/4/14

#
public boolean isFalling()
    {
        if (this.getWorld() != null)
        {
            return (this.getGridY() < 
                this.getWorld().getHeight() - 1
                && this.getWorld().getOneObjectAtOffset(this.getGridX(),
                    this.getGridY() + 1, Particle.class (== null);
        }
        return false; 
    }
danpost danpost

2020/4/14

#
I said move it -- not change it. Line 8 should be:
this.getGridY() + 1, Particle.class) = null);
Atharva1912 Atharva1912

2020/4/14

#
danpost wrote...
I said move it -- not change it. Line 8 should be:
this.getGridY() + 1, Particle.class) = null);
Got it Thank you so much
You need to login to post a reply.