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

2012/5/21

Code Writing

Psychman Psychman

2012/5/21

#
I just started using Greenfoot and i was trying to type code I wrote simple commands like move(4); and it worked but when i write a user input control like when key left pressed and all that stuff it says i have an error in the code
kartikitrak kartikitrak

2012/5/21

#
What is the error?
davmac davmac

2012/5/21

#
and what is the code?
IsVarious IsVarious

2012/5/22

#
Can you post a copy of the code you're working with, and clearly what error you were getting?
kartikitrak kartikitrak

2012/5/22

#
I love how I asked for error, davmac asked for code and isVarious asks for both.
danpost danpost

2012/5/22

#
Actually, davmac was asking for both also. He started with the word 'and'!
kartikitrak kartikitrak

2012/5/22

#
Fair enough.
Psychman Psychman

2012/5/24

#
1
2
3
4
5
move(4);
      if(atWorldEdge())
      {
        turn(13); 
      }
that is a copy of the code i inserted i wanted my object to turn when it hits the egde of the screen and this is the error that i got "cannot find symbol- method atWorldEdge()"
dlanni dlanni

2012/5/24

#
'atWorldEdge( )' is not a built-in method. It was created, probably by Mik, to help beginners without overwhelming them with a lot of code writing ( see http://blogs.kent.ac.uk/mik/category/joy-of-code/ #10). The code to create atWorldEdge is usually hidden in a facilitator class between Actor and player class, sometimes called Mover or Animal. If you insert this, it will work: public boolean atWorldEdge() { if(getX() < 20 || getX() > getWorld().getWidth() - 20) return true; if(getY() < 20 || getY() > getWorld().getHeight() - 20) return true; else return false; }
Psychman Psychman

2012/5/24

#
dlanni wrote...
'atWorldEdge( )' is not a built-in method. It was created, probably by Mik, to help beginners without overwhelming them with a lot of code writing ( see http://blogs.kent.ac.uk/mik/category/joy-of-code/ #10). The code to create atWorldEdge is usually hidden in a facilitator class between Actor and player class, sometimes called Mover or Animal. If you insert this, it will work: public boolean atWorldEdge() { if(getX() < 20 || getX() > getWorld().getWidth() - 20) return true; if(getY() < 20 || getY() > getWorld().getHeight() - 20) return true; else return false; }
Okay, thanks
IsVarious IsVarious

2012/5/24

#
kartikitrak wrote...
I love how I asked for error, davmac asked for code and isVarious asks for both.
lol Sometimes it takes 3 people to ask for the same thing.
DoctorrBoss DoctorrBoss

2014/1/7

#
Psychman wrote...
'atWorldEdge( )' is not a built-in method. It was created, probably by Mik, to help beginners without overwhelming them with a lot of code writing ( see http://blogs.kent.ac.uk/mik/category/joy-of-code/ #10). The code to create atWorldEdge is usually hidden in a facilitator class between Actor and player class, sometimes called Mover or Animal. If you insert this, it will work: public boolean atWorldEdge() { if(getX() < 20 || getX() > getWorld().getWidth() - 20) return true; if(getY() < 20 || getY() > getWorld().getHeight() - 20) return true; else return false; }
When I write down that code, it says return outside method. What do I do??????
danpost danpost

2014/1/7

#
I would be hard to say considering how you do not show how you implemented it.
You need to login to post a reply.