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

2017/2/20

If it's facing in a certain direction.

OKNEM OKNEM

2017/2/20

#
I would like to create some code, I've already got half. Here's what I've got:
if (?)
{
     setDirection(270);
}
I would like the question mark to be a method that indicates when the object is facing between 1 and 180 degrees. So when the object is facing up or down, it automatically turns left again. Thanks for your help. EDIT: I obviously need something to do with getRotation.
aldrisang aldrisang

2017/2/20

#
I'm pretty new at it myself, but I'd imagine something like:
if (getRotation() >= 1 && getRotation() <= 180) { code }
OKNEM OKNEM

2017/2/20

#
Awesome, it works. Thanks heaps. :)
aldrisang aldrisang

2017/2/20

#
Yay. Welcome. :)
OKNEM OKNEM

2017/2/20

#
Hmm... it's a bit... unorganized. I want to make it so that I can make it stop there once it hits 180 degrees and 0 degrees. Just stop. Don't go back to the 270 degrees, just stay there. Like there's an invisible barrier there. So far I've got this:
private int getRotation;
    private void checkTurn()
    {
        if(getRotation() = 1)
        {
            setRotation(1);
        }
        if(getRotation() = 180)
        {
            setRotation(180);
        }
        
    }
...but there's an error in the parentheses after getRotation. Specifically, it says it expected a variable, not a value. If I take out the parentheses, it says you can't convert an int to boolean. Help? @aldrisang
OKNEM OKNEM

2017/2/20

#
Aha. Got it. Needed two equals signs. Thanks for the help! :D
You need to login to post a reply.