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

2013/3/22

Keeping a counters amount??

1
2
3
danpost danpost

2013/3/22

#
Just that the line CoinCounter coincounter = new CoinCounter(); in the 'addCoins' method of the Cannon class can be removed. You are creating a new CoinCounter object that is local to the method, but not doing anything with it; it will be flagged for garbage collection as soon as the method has completed.
RedManRocket RedManRocket

2013/3/23

#
Hello i have been trying to figure it out myself but what has ended up happening is that in the code above the retry button is resetting the variable money, so what is happening is it is displaying the right amount of money until i get another coin then it resets it self, any ideas.
RedManRocket RedManRocket

2013/3/23

#
Hello i have been trying to figure it out myself but what has ended up happening is that in the code above the retry button is resetting the variable money, so what is happening is it is displaying the right amount of money until i get another coin then it resets it self, any ideas.
danpost danpost

2013/3/23

#
Try replacing 'setValue' in the code I provided with 'addCoins'.
RedManRocket RedManRocket

2013/3/23

#
that did not work, here is something i was considering, what if i have the CoinCounter itself bring along its own data to the world instead of having the cannon and the retry button do it???
danpost danpost

2013/3/23

#
That would take more complicated code than bringing the value(s) over because then you would have to remove and replace the objects in the new world. Upload your scenario with source code so I can look at what you are dealing with. I can let you know when I have it so you can delete it off the site, if you wish.
RedManRocket RedManRocket

2013/3/23

#
No you can keep it on but i will do that momentarily
RedManRocket RedManRocket

2013/3/23

#
I just uploaded it you can find it in scenarios or on my profile it has your name tagged in it its called space Invaders Part 3 Version 3 RedManRocket
danpost danpost

2013/3/23

#
I figured out the the value we are trying to pass is in the Cannon class and the one line in the RetryButton class needs to be written as:
space.returnCannon().addCoins(oldSpace.returnCannonCoins().getValue());
RedManRocket RedManRocket

2013/3/23

#
this is the error message it gave me cannot find symbol - method addCoins(int)
danpost danpost

2013/3/23

#
You will probably run into all sorts of complications because you are trying to track values at multiple locations. You should be able to use the same Counter class for both the life-counter and the coin-counter. The values of both the lives and coins should be in the Counter class only as the counter value. You can create two instances from the Counter class and name them appropriately in your world class. Something like this:
public Counter lifeCounter = new Counter("Lives ");
public Counter coinCounter = new Counter("Coins ");
You can still have the methods to return the counter objects in your world class code. You should not have any methods anywhere to change the value of the counters except in the counter class. The proper way to add coin value to the coin counter from an actor class is to use the following:
((Space)getWorld()).getCoinCounter().add(10);
or to decrement the life counter and then check for zero, use:
((Space)getWorld()).getLifeCounter().add(-1);
if (((Space)getWorld()).getLifeCounter().getValue() == 0)
{
    // add objects here (RetryMenu and RetryButton)
}
By doing code like this, you only have one field for each stat; and confusion is much less likely to occur. Keeping track of everything is much easier, also.
danpost danpost

2013/3/23

#
I did not get that error when I modified the code to that. Let me test it again. Just one moment.
danpost danpost

2013/3/23

#
I do not get an error changing line 41 in your RetryButton class to that line given above. Copy/paste that line into your code and try it again.
RedManRocket RedManRocket

2013/3/23

#
is there a way i can get a copy of the project you just modified?
danpost danpost

2013/3/23

#
Download your own scenario and change that one line as prescribed above.
There are more replies on the next page.
1
2
3