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

2016/11/19

Why can't I reload delay count?

Astralman Astralman

2016/11/19

#
reloadDelayCount is underline in red. What's wrong with it? What am I missing? Does this method delay an action?
public Ship ()
    {
        reloadDelayCount = 5;
        Vector intial = new Vector(Greenfoot.getRandomNumber(360), .6);
        setRotation(270);
    }
Astralman Astralman

2016/11/19

#
Says "Cannot find symbol"
Super_Hippo Super_Hippo

2016/11/19

#
You need a line like this in the class:
private int reloadDelayCount;
Astralman Astralman

2016/11/19

#
And does this delay an action?
Super_Hippo Super_Hippo

2016/11/19

#
No, this does not delay anything, but the error occurred because the line was missing. The question is what you want to delay.
Astralman Astralman

2016/11/19

#
So I'm using the wrong method? The initial movement.
Super_Hippo Super_Hippo

2016/11/19

#
You can delay it in the act method. Decrease the variable every act cycle and as long as it is above 0, exit the act method, so it does not do anything.
Astralman Astralman

2016/11/19

#
I'm confused you tell me to use it in the act method and then exit the act method. Just write it in code because it will be easier to understand.
Super_Hippo Super_Hippo

2016/11/19

#
private int delay = 300;

public void act()
{
    if (delay>0)
    {
        delay--;
        return;
    }
    //rest of act method
}
danpost danpost

2016/11/19

#
If the 'reloadDelayCount' does what I think it does then something like this:
private int reloadDelayCount;

// in act (or in a method it calls)
if (reloadDelayCount > 0 && --reloadDelayCount == 0) shots += 10; // adjust value as needed

// after firing a shot
if (--shot == 0) reloadDelayCount = 300;// adjust value as needed
You need to login to post a reply.