0

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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Will 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 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! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.