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

2012/11/28

Hey

BradH BradH

2012/11/28

#
mport greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class KnightSpawnButton here. * * @author ( BradH) * @version (a version number or a date) */ public class KnightSpawnButton extends GoodTroops {private Counter counter; public KnightSpawnButton(Counter pointCounter) { counter = pointCounter; } /** * Act - do whatever the KnightSpawnButton wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() {click(); no(); nospawn(); } public void click() { getWorld().addObject(new Knight1(), 45 , 306); if (Greenfoot.mouseClicked(this)) Greenfoot.playSound("swordspawn1.wav"); if (Greenfoot.mouseClicked(this)) counter.subtract(2); } //if counter < 2 call on no spawn method public void no() { (counter.getValue() < 2){ nospawn)(); } } //if mouse is clicked do nothing public void nospawn() { if (Greenfoot.mouseClicked(this)) } I need to put in a line of code in my nospawn method that would allow the Actor to spawn nothing if the counter is less than 2, any ideas?
Spilli Spilli

2012/11/28

#
Do you mean something like;
public void nospawn() {
     if(counter.getValue() < 2) {
          return;
     }

     if(Greenfoot.mouseClicked(this)) {
     }
}
BradH BradH

2012/11/28

#
I have a counter in my game that gives me money and when the counter value is less than 2 I want the button to not spawn knights until the counter value is greater than 2.
Spilli Spilli

2012/11/28

#
Ok, post the method which spawns the knights when the mouse is clicked.
BradH BradH

2012/11/28

#
It is under the click method(I forgot to copy part of the code< my bad haha) public void click() { if (Greenfoot.mouseClicked(this)) getWorld().addObject(new Knight1(), 45 , 306); if (Greenfoot.mouseClicked(this)) Greenfoot.playSound("swordspawn1.wav"); if (Greenfoot.mouseClicked(this)) counter.subtract(2); }
Spilli Spilli

2012/11/28

#
Lol ok, so try this:
public void click() {
     if(Greenfoot.mouseClicked(this)) {
          if(counter.getValue() >= 2) {
               getWorld().addObject(new Knight1(), 45, 306);
               counter.subtract(2);
          }
          Greenfoot.playSound("swordspawn1.wav");
     }
}
Hopefully that should work.
BradH BradH

2012/11/28

#
Nice It works thanks man
Spilli Spilli

2012/11/28

#
Great :) Is there anything else I can help you with?
BradH BradH

2012/11/28

#
Thats it for now
Spilli Spilli

2012/11/28

#
Ok ;)
You need to login to post a reply.