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

2019/1/13

how to recognize a key press. https://www.greenfoot.org/topics#

Ipurplish Ipurplish

2019/1/13

#
I tries using this line: if(isKeyDown("w")) { } and I got an error that says "cannot find symbol". Please help!
danpost danpost

2019/1/13

#
Ipurplish wrote...
I tries using this line: << Code Omitted >> and I got an error that says "cannot find symbol". Please help!
The isKeyDown method is a member of the Greenfoot class. It is not in the class you are calling it from. You must (dot) prefix the call with the class name: YAY! Greenfoot.isKeyDown(...
Ipurplish Ipurplish

2019/1/13

#
thankyou
danpost danpost

2019/1/13

#
Ipurplish wrote...
thankyou
Footnote: Prefixing with a class name only works on methods that are declared static. Non-static methods must be called on an object (or, instance) of the class the method is found in.
data17 data17

2019/1/13

#
That means all methods in the class greenfoot.Greenfoot works only with the class Greenfoot as prefix as danpost explaned! (Example Greenfoot.setWorld(), Greenfoot.getKey() and so on...) Because they are all static. See in the Greenfoot.API All other classes in the greenfoot package are non-static methods except some greenfoot.UserInfo() methods.
You need to login to post a reply.