Ok. I got it. If you want you can go to the scenario and under the big 'Open in Greenfoot' button on the right in small print, you will find 'edit scenario / delete scenario / get data' and delete it back off the site.
Ok. The value of 'small' that the Healthbar object contains is being set to 'Infinity' due to the fact that MaxHealth in the tank class (as well as in the Healthbar class) have not been set to any value, yet. So, you were dividing by zero and coming up with 'Infinity' for its value; which in turn exceeded the VM limit for what you were using the value for. I changed both 'MaxHealth' values to '200' and the error went away.
Well maxhealth is changed throughout the game (when you upgrade the armor), will I still be able to change it when that happens? And maxhealth should be getting set in the tank's constructor function or the once boolean if statement, getting the data from DATA
Ok so I changed maxhealth to one, but now the turret gun doesn't point at the tank anymore and the gun is staying on top of the health bar instead of the tank. Is that what yours was doing?
And maxhealth should be getting set in the tank's constructor function or the once boolean if statement, getting the data from DATA
That may be; however, the Tank object never gets a chance to act and set those values before the Healthbar tries to use it. This is because of the way you are using 'once' in the classes. All one-time actions that can be performed without the needing the objects in the world should be done within the constructor of the class; and all one-time actions that require the actor be in the world should be done in the 'addedToWorld' method of the class (it is an Actor class method that by default is empty, and is called automatically when you 'addObject' the object into a world).
Also, I see you still have poor subclassing issues.
Ok so I changed maxhealth to one, but now the turret gun doesn't point at the tank anymore and the gun is staying on top of the health bar instead of the tank. Is that what yours was doing?
Yes. Mine was doing that also. That is due to your poor subclassing issues. By having Healthbar extend Tank, it is considered a Tank object (just like it is considered an Actor object, which Tank extends). So, the gun is using the first element in the list of, now, multiple Tank objects to set its location to; and, at the moment, that first element is the Healthbar Tank object (I phrased it like that so you could better understand the issue).
I think I understand the issue. Thank you so much for helping, what do you suggest I do about the subclass issue? Not have any at all? And I don't understand why the turret gun doesn't work anymore or the gun not staying on the tank.
One last question (if you don't mind) now that I have made these changes, the game is slow and doesn't run smoothly, any ideas on what could be causing that?
One last question (if you don't mind) now that I have made these changes, the game is slow and doesn't run smoothly, any ideas on what could be causing that?
Yes. It seems that every actor is setting its image every act cycle when with most of them you only need to set it once in the constructor (instead of the act).