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

2012/1/26

Help with page 33 in the book

joeylad joeylad

2012/1/26

#
Will somebody send me the complete correct code for Eating worms. Code 3.2 as shown isn't sufficient for me I fear because I keep getting errors which I don't understand.
danpost danpost

2012/1/27

#
What is Code 3.2 as shown (list code on your post), and exactly what error message are you getting (copy and paste on your post)? It would also help if you made a reference to what line number (in the class) the code you post starts at.
nccb nccb

2012/1/27

#
I have the book here, and the sample looks fine to me. What are the errors you are getting, exactly? With that info, we can help to track down the problem, but here's a couple of thoughts:
  • The book chapter is similar to the online tutorials, but the online tutorials use a slightly different scenario. If you're using the book, make sure you started with the little-crab scenario that comes with the book, not the one that's online
  • The code shown in 3.2 still needs the class declaration around it. That is, the code in 3.2 replaces the middle of 3.1 (the public void act bit), but you still need the outermost parts from 3.1
joeylad joeylad

2012/1/31

#
danpost danpost

2012/1/31

#
Do you see what bracket you have there? It looks square to me. It should be curly!
danpost danpost

2012/1/31

#
Looking at the code you provided, it appears you mixed up your classes. You show here the Worm class extending the Crab class, where Worm should extend Actor, and the code within the act() method provided should probably be in the Crab class (I do not believe that you want the worms moving around your world). The act() method for the Worm class should probably be empty (or non-existant).
joeylad joeylad

2012/2/1

#
Many thanks to you both and danpost in particular (I like your fractal) - I see my error(s) and I'll correct them and move on or report back if I'm stuck.
You need to login to post a reply.