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

2012/12/30

classes interacting with each other

bonana bonana

2012/12/30

#
hey everyone, i've got 2 questions for you, i hope you know an answer for both, but i also would be happy with one solution ;-)

Problem 1

in my class i've got a method to do something, which after doing so, adds +1 to a counter also in this class. there are 3 subclasses. the problem is, that everytime i call the counter, it gives me the counter of one of my subclasses, but i want all 3 counters together. how can i create a counter that contains all 3 counters?

Problem 2

i want my world to give me some text, containing the counter of subclass 1, the counter of subclass 2 and the counter of subclass 3. how can i make my world use the 3 counters in its text?
bonana bonana

2013/1/1

#
does nobody know a solution? :-(
danpost danpost

2013/1/1

#
Problem 1: no matter how you go about it, all three counters must be incremented individually. Problem 2: set the text to counter of subclass1 \n counter of subclass2 \n counter of subclass3.
danpost danpost

2013/1/1

#
I realize my responses were quite generalized; but, without more information or code, that is about all that can be replied with. Also, to be more explicit, by saying 'counters must be incremented individually', this does not mean you cannot use a loop to increment all three counters from the world with something like the following:
for(Object obj : getObjects(Counter.class)) ((Counter)obj).add(1);
You need to login to post a reply.