I have a bunch of objects in an array in Greenfoot, when act(loop that keeps game going) runs I need to get some information about the array from within the object that belongs to it. What ways are there for getting information about the array from within the objects it contain?
Asked
Active
Viewed 154 times
1 Answers
1
Store a reference in the object to the list. For example:
class MyObject {
List owner;
// ...
public void setOwner(List owner) { this.owner = owner; }
}
In this way, you can access to the owner list from any method in MyObject. When you add the object to the list, don't forget to call the "setOwner" method.

Miguel Prz
- 13,718
- 29
- 42
-
1Will work. But I have to wonder, if you require info about a container in the contained elements, there might be a design issue. – G_H Oct 24 '11 at 20:29
-
G_H was right, i changed the approach and it was alot easier to solve the task. I am however grateful for your answer Miguel Prz, I did learn from it! :) – nenne Oct 24 '11 at 22:17