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

2018/4/16

Indefinite adding of object.

Ruskii Ruskii

2018/4/16

#
Hello, I am trying to make it so that when all of the enemies in a world are gone, it adds an object to that world. My issue is that after all of the enemies have been killed, it adds the object hundreds of times and will in turn lag out the game. I need to know how to make it add only one object. Here is my code:
public void allowAccess()
    {
          if (getObjects(Enemy.class).isEmpty()) 
        {
            GatewayTwo gatewaytwo = new GatewayTwo();
            addObject(new GatewayTwo(), 1277, 541);
        }
    }
Yehuda Yehuda

2018/4/16

#
Add a condition to the if-statement that (the block should be executed) only when there are no GatewayTwo Objects in the World, that way if there is (at least) one already no more will be added.
Ruskii Ruskii

2018/4/16

#
Yehuda wrote...
Add a condition to the if-statement that (the block should be executed) only when there are no GatewayTwo Objects in the World, that way if there is (at least) one already no more will be added.
Thank you for the response; it works perfectly.
You need to login to post a reply.