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

2012/11/17

getRotation / setRotation issues

Dob Dob

2012/11/17

#
Hello! I am working on Greeps and I am quite confused with get/ set Rotation methods. This is the piece of code that compiles: setRotation (getRotation() + Greenfoot.getRandomNumber(2) * 180 - 90); And the piece which does not compile: setRotation(getRotation() + turn (90)); It states that void type is not allowed there. Can anyone explain why does the first piece of code compile and the second one does not? Additionally I was trying to use spit("Colour") to leave the trail on the map, but I think I am missing something (greenfoot states "cannot find symbol - method spit"). What do I do wrong?
Zamoht Zamoht

2012/11/17

#
void turn(int amount) Turn this actor by the specified amount (in degrees). This is the information that the api gives about the turn method. So basicly your problem is that you're using a void method as an arguement where an integer was expected. A fix here would be to just remove the "turn".
danpost danpost

2012/11/17

#
As far as calling the 'spit' method: in the 'Greeps' scenario, you are only allowed to edit/write code within the 'Greep' class. That class is supposed to be a sub-class of 'Creature', which contains the 'spit(String)' method. So, either you somehow removed the method from the 'Creature' class or you did not put the call in the 'Greep' class. If neither of these are the case, you need to be more explicit as to where and how you are using that code.
Dob Dob

2012/11/18

#
Thanks for your answers guys. I understand what was the mistake with turn(). @danpost I think I might have a different version of Greeps. There is no 'Creature' class, the class which I am allowed to edit is called 'MyGreep', and it is subclass of 'Greep'. There is also another subclass of the 'Greep' class, which is called 'Simple Greep'. I am quite sure I did not delete anything from any class that I am not supposed to edit and that there was no 'spit' method anywhere in 'Greep' class. Do I have a wrong version of 'Greeps' scenario?
danpost danpost

2012/11/18

#
Well, we obviously do not have similar versions at all. Mine may be an old one; or, maybe one for a more basic class. I never did have any formal training in Java (or Greenfoot) and do not recall from where I came about acquiring the source. But I have seen several scenarios uploaded on the site that looked like they were the same.
You need to login to post a reply.