-1
    global bullet
    global ball
    global ball_x
    pred1 = [bullet, ball]
    pred2 = random.choice(pred1)
    process = image(pred2, ball_x, 10)
time.sleep(0.5)

ball_x = [100, 200, 300]

I need to know how I can program the "process" to repeat itself after the "0.5" second and then sleep again for another "0.5" seconds and so on repeating this process forever.

3 Answers3

0

If you want to put process in an endless loop with a 0.5 second delay, you could do something like this

while True:
    process = image(pred2, ball_x, 10)
    time.sleep(0.5)
Eric M
  • 1,360
  • 11
  • 19
0

First add import time or from time import sleep. Then in a while True: loop do time.sleep(0.5)

Thomas
  • 1,214
  • 4
  • 18
  • 45
0

You can try the code below, it will alternate between sleeping and throwing ball then take a rest.

global bullet
global ball
global ball_x
pred1 = [bullet, ball]
throw = False
while true:
    pred2 = random.choice(pred1)
    if throw:
        time.sleep(0.5)
        throw = False
    else:
        process = image(pred2, ball_x, 10)
        time.sleep(0.5)
        throw = True