The code -
if(Greenfoot.isKeyDown("left")
{ turn(3);
}
does not seem to work with "Act" . This works with "Run" but not with "Act"
What am I doing wrong? Thanks
Maybe that's because when you hit act, the object turns a little bit, so you don't see it.
And i give you this advice:
if(Greenfoot.isKeyDown("left")
{
}
I think the run key works differently than 'act'. From the crab tutorial -
With the following code: if I hold down the right arrow key and press "Act" the crab moves in a straight line. If I press "Run" and hold down the right arrow key, the crab goes in a circle. So "Act" does not seem to respond the same as "Run" for this example in the tutorial.
public void moveAndTurn()
{
move(4);
if(Greenfoot.isKeyDown("left"))
{
turn(-3);
}
if(Greenfoot.isKeyDown("right"))
{
turn(3);
}
}
That's right, the keystrokes aren't processed while the scenario isn't running, so even if you press "right" and hold it down while you click "Act", it will not register as being down. It's just the way it works.
@rdlatimer I don't think you are right. When you press act, every object will run the action act(). When you press the run button, Greenfoot simply runs the act() action for every object in the world, the whole time. So actually, the run button in Greenfoot just runs a loop where every object will run the act() method. I hope this lets you understand Greenfoot al little better.
(If you're wondering where I got this information: from the Greenfoot book)