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

2017/4/30

Can anyone see my Mistake, why doesn't it work?

1
2
danpost danpost

2017/5/1

#
Unknown6415 wrote...
But I have many Attackers, not only the Gunner, who should use this method, and they should have their own time1 and time2.
Do not worry, each object created from the Gunner class and from any other class that extends Attacker will have their own time fields
Yehuda Yehuda

2017/5/1

#
Unknown6415 wrote...
But I have many Attackers, not only the Gunner, who should use this method, and they should have their own time1 and time2.
But that's not so complicated. It's just two variables (and you don't really need the time2 variable from what you've shown) and then the method with one if and then one line of code in the if. (Each instance that you create of a class will have it's own variables which is what you want.)
Unknown6415 Unknown6415

2017/5/1

#
And how can other classes acces to the time of the gunner? until now I did it with Gunner.time1 becuase the time was public static int but now it doesn't work that way
Yehuda Yehuda

2017/5/1

#
Unknown6415 wrote...
And how can other classes access to the time of the gunner? until now I did it with Gunner.time1 because the time was public static int but now it doesn't work that way
You have multiple classes all running on the same reload time? (or each gun will have its own reload time) I don't see why you you're having more than one gunner or gun running on the same reload time.
danpost danpost

2017/5/1

#
Unknown6415 wrote...
And how can other classes acces to the time of the gunner? until now I did it with Gunner.time1 becuase the time was public static int but now it doesn't work that way
The Gunner class is an extension of the Attacker class. Every object from any class that extends the Attacker class will get their own instance of any non-private, non-static field declared in the Attacker class. They even get the private ones; but do not have direct access to those fields.
You need to login to post a reply.
1
2