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

2021/6/23

How long does it take for code to run?

Gabe1098 Gabe1098

2021/6/23

#
How long does it take for code to run? because I notice that there is a delay when the code runs because of this
if (Greenfoot.getRandomNumber(500) < 1) {
            addObject(new Spider(),0,Greenfoot.getRandomNumber(400));
        }
if there is no delay then it would just spawn spiders EVERYWHERE and it would be FILLED on the screen but it takes about a good 15 seconds for a spider to spawn
danpost danpost

2021/6/23

#
Show full method lines above are in and indicate what class that method is in. Also show Spider class codes.
Gabe1098 Gabe1098

2021/6/23

#
danpost wrote...
Show full method lines above are in and indicate what class that method is in. Also show Spider class codes.
I don't have a mistake I have a question, how long does it take for the "if" or "while" loop takes to run
danpost danpost

2021/6/24

#
Gabe1098 wrote...
how long does it take for the "if" or "while" loop takes to run
"if" is immediate, but the contents of its code block may take time. I guess the calculation of the conditional expression (before the "if" is executed) could also come into play. "while" could run indefinitely, if the condition to loop never fails.
danpost danpost

2021/6/24

#
In your code above, the ONLY thing that may cause a delay is something stemming from "new Spider()", which executes "public Spider()" in your Spider class. Hence, why I asked for its codes.
Gabe1098 Gabe1098

2021/6/24

#
danpost wrote...
In your code above, the ONLY thing that may cause a delay is something stemming from "new Spider()", which executes "public Spider()" in your Spider class. Hence, why I asked for its codes.
Ohhh Thanks!
You need to login to post a reply.