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

2017/11/6

Giving an object a specific instance of an object to follow.

Beamo Beamo

2017/11/6

#
Hi! My query this time is in regards to if it's possible to make an object (briefcase) follow a specific instance of another class (grunt). There will be multiple instances of the grunt class. Any ideas? Thanks!
danpost danpost

2017/11/6

#
You could just have the specific grunt keep the briefcase with him. You would add an instance field to hold a reference to a briefcase. Assign the briefcase to the field of the grunt that is to have one and leave all the others with a null value. At the end of the act method, ask if the reference is null. If not, move it to a position that is some offset to the position of the grunt.
Beamo Beamo

2017/11/7

#
Thanks for the reply danpost! But how would I differentiate between the different instance fields?
danpost danpost

2017/11/7

#
Beamo wrote...
Thanks for the reply danpost! But how would I differentiate between the different instance fields?
Do you already have a specific grunt to assign the briefcase to? if not, how are you to determine which grunt the briefcase is to follow?
You need to login to post a reply.