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

2013/2/17

Exercise 5.4/5.5 in Greenfoot - Making on-screen piano

PBnJwFluff PBnJwFluff

2013/2/17

#
Can someone please help me. I am working on exercise 5.4/5.5 where I'm trying to make the piano keys alternate between up and down. Here is the code that I'm copying directly from the book and I keep getting an error of "Cannot find symbol variable isDown" import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) public class Key extends Actor { /** * Create a new key. */ public Key() { } /** * Do the action for this key. */ public void act() { if ( !isDown && Greenfoot.isKeyDown("g") ) { setImage ("white-key-down.png"); isDown = true; } if ( isDown && !Greenfoot.isKeyDown("g") ) { setImage ("white-key.png"); isDown = false; } } }
danpost danpost

2013/2/17

#
You have not declared any fields for this class; the compiler has no idea how to deal with 'isDown' as it does not know what it is. 'isDown' should have been declared as a boolean field after the first open squiggly bracket.
PBnJwFluff PBnJwFluff

2013/2/17

#
aaahhh okay thank you! I appreciate the help!!!
You need to login to post a reply.