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

2020/8/1

Random

Roshan123 Roshan123

2020/8/1

#
How will i get Random number at every 3 seconds if Greenfoot.isKeyDown("q"); I want the random number to be changed at every 3 seconds. Plz anybody help me
danpost danpost

2020/8/1

#
With scenario at standard running speed ('50' or middle of slide bar), something like the following should work:
private int qTimer, qValue;

public void act()
{
    if (qTimer == 0)
    {
        qValue = Greenfoot.getRandomNumber(10);
        qTimer = 180;
    }
    else qTimer--;
}
Roshan123 Roshan123

2020/8/1

#
Why you have written private in line 1 Plz can you explain me in the most easiest words What is the difference between int qTimer; and private int qTimer;
danpost danpost

2020/8/1

#
Roshan123 wrote...
Why you have written private in line 1 Plz can you explain me in the most easiest words What is the difference between int qTimer; and private int qTimer;
For you, right now, not really much. However, a private field is only accessible within the class it is declared in (or, rather, by the object the field belongs to). If not private, other classes, or objects, in your project would be able to access and change the value of the fields. Since the fields are only pertinent to the object they were created for, making them private only makes sense.
Roshan123 Roshan123

2020/8/3

#
Its not working I used showText It shows that the qTimer is not increasing
danpost danpost

2020/8/3

#
Roshan123 wrote...
Its not working I used showText It shows that the qTimer is not increasing
Show codes. Also, it would never increase, anyway. It would be set (from zero) to 180 and decrease from there.
You need to login to post a reply.