Hi, I'm hoping someone can help me. This is my first attempt at writing a Java game (bat_and_ball) and I've got stuck.
It sounds like a simple problem but I've tried everything I can think of and still no joy.
I need my ball to look up the Y co-ordinate (called z) of the bat to see whether it stays in play or goes out. However, when my ball looks up z with using bat.z I get the error "cannot resolve symbol - symbol:variable bat - location class Ball". Here is the important part of the code:
When it compiles bat.z it says "cannot resolve symbol - symbol:variable bat - location class Ball"
But I know that the object bat exists and has a z variable. Here is the code that defines the bat:
I think your question has been answered above, but I'd like to add a few comments. First of all, class names should begin with upper case, so "class player" should be "class Player". This isn't required, but it is good to follow conventions like this when you ask questions. It also helps when you come back to your code at a later time.
p.s. The above shows you an example of how to fix your code, but it isn't the only solution. I suggest you do a search on this board (or the web) for something like "variable scope". This is the general topic that describes when a variable can be accessed (or not). [ August 23, 2004: Message edited by: Layne Lund ]