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

2016/1/14

Accessing another class (inside of class, not world)

2
3
4
5
ObjektnoPR ObjektnoPR

2016/1/18

#
No, i was wrong. Its not the 40th line inside of Mesto enabeling spaming scores, but i think it need to be fixed inside if sentence (26 line) of Letalo class
danpost danpost

2016/1/18

#
I cannot tell why you are now getting an OutOfMemoryError. However, I do know that you have placed the line to change destinations at the wrong location. Using your last Mesto class posting, cut line 36 and insert it at line 31. As far as score spamming, I guess you will need to track the instances of change in the state of the space key (instead of its continuous state):
public class Mesto extends Actor
{
    private Actor cityImage = new SimpleActor();
    private GreenfootSound hoverSound;
    public boolean spaceDown;
 
    public Mesto(String ime){
        setImage("mesto.jpg");
        hoverSound = new GreenfootSound(ime + ".mp3"); 
        cityImage.setImage(ime + ".jpg");
    }
    
    public void act(){
        if (downDown != Greenfoot.isKeyDown("down")){
            downDown = !downDown;
            if (downDown && isTouching(Letalo.class))
                Start start = (Start)getWorld();
                if (start.izbranoMesto == this){
                    hoverSound.play();
                    start.addObject(cityImage, 500, 300);
                    start.points.points += 10;
                    start.izberiMesto();
                }
                else
                {
                    start.points.points -= 5;
                }
            }
        }
        if (!hoverSound.isPlaying() && cityImage.getWorld() != null){
            getWorld().removeObject(cityImage);
        }
    }
}
I do not thing that having 'moving' changed back to an 'int' fields would help at all in the Letalo class. If both the 'up' and 'down' keys are pressed at the same time, you would have an issue, however. You may have to introduce a boolean to track the 'down' key to check for changes in its state -- just like was done in the current post of the Mesto class.
ObjektnoPR ObjektnoPR

2016/1/18

#
Yes, i also don't think so anymore, as I figured that wasn't the case.:) I will tell you if this worked as soon as I get home
ObjektnoPR ObjektnoPR

2016/1/18

#
(it's hard to load this page on my phone, so I can't check if I told that it was only spamming in a wrong city. If you landed outside/in correct city it wasn't possible to spam scores
danpost danpost

2016/1/18

#
Sorry, when I corrected the name of the boolean field throughout the code above from 'spaceDown' to 'downDown', I missed changing the one on line 5 where the field is declared.
ObjektnoPR ObjektnoPR

2016/1/19

#
I noticed, don't worry :D And i fixed the code and now everything works.:D I will post my code for Mesto tomorrow (i did it a bit diferent, i solved that spamming problem). Thank you for all you help, i couldn't done it without you.
You need to login to post a reply.
2
3
4
5