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

danpost's Comments

Back to danpost's profile

In the ball class, in the 'checkFly' method, add the following line inside the if(fly != null) block: ((Counter)world.getObjects(Counter.class).get(0)).add(5);
To fix the ball out error: in the 'act' method of the Ball class, switch the order of the 'checkOut' and 'checkFly' calls. Also, in the 'checkOut' method, remove the 'gameOver' call. Will reply about counter shortly.
The 'Publish source code' checkbox was not checked on your last upload.
Either re-share the scenario with the 'Include source code' checkbox checked or start a discussion supplying the code you have so far and an explanation of what is not working properly.
Too fast. I do not even have time to move my hand from the mouse to the keyboard to make the first turn.
Every act cycle you are creating a NEW class1 object (it would not take long for this to slow down your scenario) and then getting the initial value of the newest object created. Do not create the class1 object in the act method. You should probably have an instance object field for the bar object; and you can create the object while you declare the field with the following (in class2): private class1 c1 = new class1(); Next, for testing purposes, change your act method to the following (in class2): public void act() { if ("up".equals(Greenfoot.getKey()) { c1.add(1); System.out.println(""+c1.getValue1()); } } Make sure you add this method to the class1 code: public void add(int amount) { Value1 += amount; updateImage(); } Now, compile the scenario, start it and press the "up" arrow key a few times to test it out. If you continue to have problems, start a new discussion thread and post the class1 code with a description of how it is not doing what you want.
danpostdanpost

2013/2/26

The problem is not with your scoreboard. It is with your counter (or should I say counter[b][i]s[/i][/b]. You should only have one counter; either in the Pasaulis world class or in the Gyvanai actor class. If in the world class you will need another method to get either the counter itself or the value of the counter ('public Counter getCounter' or 'public int getCounterValue'). You must get a reference to this same counter anytime you wish to change or retrieve its value. My suggestion to you is to have it in the Pasaulis world class due to the fact that you are changing its value from one actor class and retrieving its value from another when the game ends. Go through your code and make sure you only have one Counter object. Also, there is no need to have a field for the Scoreboard object. When the game is decidedly over, get the value of the counter and create a new Scoreboard on the spot to add to the world.
@Super_Hippo, It works fine for me; but I think I know why it is not working for everyone. I will try to rectify the issue as soon as possible. Thanks.
@AD12, please refer to [url=http://docs.oracle.com/javase/tutorial/java/index.html]Learning the Java Language[/url] for information on fields et al.