RuntimeError: Run loop already active. #1754
-
In previous versions of pybricks (3.4 I believe), I was able to run a 'run_task' from within a task within a multitask, but as of v3.5.0, and in the beta version, it now throws the error "RuntimeError: Run loop already active." anytime I try to do so. I'm not sure if this is a bug or feature? If it is a feature, how would I go about doing this properly? |
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment · 17 replies
-
The error is expected. To call an |
Beta Was this translation helpful? Give feedback.
All reactions
-
Can you share your code? Or, even better, a simplified example that reproduces the error? |
Beta Was this translation helpful? Give feedback.
All reactions
-
from pybricks.hubs import InventorHub
from pybricks.pupdevices import Motor, ColorDistanceSensor, Remote
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop, Axis
from pybricks.tools import wait, run_task, multitask, Matrix
hub = InventorHub(broadcast_channel=252,observe_channels=[253])
LMotor = Motor(Port.A)
RMotor = Motor(Port.B)
firstSensor = ColorDistanceSensor(Port.F)
secondSensor = ColorDistanceSensor(Port.E)
thirdSensor = ColorDistanceSensor(Port.C)
fourthSensor = ColorDistanceSensor(Port.D)
while True:
async def waiter():
await wait(10000000)
async def attractLights():
hub.light.on(Color.RED)
run_task(subtask())
async def subtask():
firstSensor.light.on(Color.RED)
async def attractMode():
await multitask(attractLights(), waiter())
run_task(attractMode()) |
Beta Was this translation helpful? Give feedback.
All reactions
-
You can move the while loop inside of async def main():
while True:
await attractMode()
run_task(main()) |
Beta Was this translation helpful? Give feedback.
All reactions
-
Oop, didn't notice the async def attractLights():
hub.light.on(Color.RED)
await subtask() Although |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you that solved it. Is there a way to run a multitask inside it? If I do that using the |
Beta Was this translation helpful? Give feedback.
All reactions
-
Can you share the code that causes the |
Beta Was this translation helpful? Give feedback.
All reactions
-
Okay so It looked like that that issue was being caused by my own bad code. But now I have another because I'm a sucker for punishment. For some reason it looks like that at line 388, the code isn't actually waiting, and somehow runs line 404 and crashes with the error "OSError: [Errno 1] EPERM: " Honestly this is just such a mess I'm considering just restarting it. I understand if you don't want to/are unable to debug this disaster. from pybricks.hubs import InventorHub
from pybricks.pupdevices import Motor, ColorDistanceSensor, Remote
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop, Axis
from pybricks.tools import wait, run_task, multitask, Matrix
hub = InventorHub(broadcast_channel=252,observe_channels=[253])
LMotor = Motor(Port.A)
RMotor = Motor(Port.B)
controller = Remote("ICBController", timeout=None)
firstSensor = ColorDistanceSensor(Port.F)
secondSensor = ColorDistanceSensor(Port.E)
thirdSensor = ColorDistanceSensor(Port.C)
fourthSensor = ColorDistanceSensor(Port.D)
controller.name("ICBController")
controller.light.off()
hub.light.off()
hub.speaker.volume(100)
#numbers
one = Matrix(
[
[50, 50, 0, 0, 100],
[50, 0, 50, 0, 100],
[50, 50, 0, 0, 100],
[50, 0, 50, 0, 100],
[50, 50, 0, 0, 100],
]
)
two = Matrix(
[
[50, 50, 0, 100, 100],
[50, 0, 50, 0, 100],
[50, 50, 0, 100, 100],
[50, 0, 50, 100, 0],
[50, 50, 0, 100, 100],
]
)
three = Matrix(
[
[50, 50, 0, 100, 100],
[50, 0, 50, 0, 100],
[50, 50, 0, 100, 100],
[50, 0, 50, 0, 100],
[50, 50, 0, 100, 100],
]
)
#star
star = Matrix(
[
[0, 0, 75, 0, 0],
[0, 50, 100, 50, 0],
[75, 100, 100, 100, 75],
[0, 100, 50, 100, 0],
[0, 75, 0, 75, 0],
]
)
#calibrate position of beam
async def calibrateL():
await LMotor.run_until_stalled(-1000, duty_limit=30)
LMotor.reset_angle(0)
async def calibrateR():
await RMotor.run_until_stalled(1000, duty_limit=30)
RMotor.reset_angle(0)
async def calibrate():
await multitask(calibrateL(),calibrateR())
run_task (calibrate())
print("calibrated")
LMotor.run_target(800, 1000, wait=False)
RMotor.run_target(800,-1100, wait=False)
#Ninty nine bottles of beer
async def playSong():
await hub.speaker.play_notes(["C4/4","C4/4","C4/4","G3/4","G3/4","G3/4","C4/4","C4/4","C4/4","C4/2","D4/4","D4/4","D4/4","A3/4","A3/4","A3/4","D4/1","B3/2","B3/4","B3/4","G3/2","B3/4","B3/4","B3/4","B3/4","G3/2","G3/4","G3/4","A3/4","A3/4","B3/4","C4/4","C4/4","C4/4","C4/2"], tempo=400)
#reset beam Position
async def resetBeam():
hub.display.off()
await controller.light.off()
LMotor.run_target(1000, 1600)
RMotor.run_target(1000,-1650)
await wait(5000)
LMotor.run_target(800, 1000)
RMotor.run_target(800,-1100)
await wait(2000)
#flash light to indicate which hole is target
async def firstLight():
for i in range(8):
await firstSensor.light.on(Color.BLUE)
await wait(250)
await firstSensor.light.off()
await wait(250)
async def secondLight():
for i in range(8):
await secondSensor.light.on(Color.BLUE)
await wait(250)
await secondSensor.light.off()
await wait(250)
async def thirdLight():
for i in range(8):
await thirdSensor.light.on(Color.BLUE)
await wait(250)
await thirdSensor.light.off()
await wait(250)
async def fourthLight():
for i in range(8):
await fourthSensor.light.on(Color.BLUE)
await wait(250)
await fourthSensor.light.off()
await wait(250)
gameState = 0
#MAIN LOOP
while True:
#define variables
timer = 0
score = 0
balls = 1
tilted = False
updateDisplay = True
firstSensor.light.off()
secondSensor.light.off()
thirdSensor.light.off()
fourthSensor.light.off()
#ATTRACT MODE
async def displayAttract():
while True:
X = 100
_ = 0
FRAME = Matrix([
[_, _, _, _, X, X, _, _, X, _, _, _, _, X, _, _, X, _, X, _, _, _, X, X, X, _, _, X, X, _, X, X, X, _, _, _, _, X, X, _, _, X, _, _, X, _, _, _, X, X, _, _, _, _, _, X, X, _, _, X, X, X, _, X, X, X, _, X, X, _, _, _, _, _, X, X, _, _, X, X, _, _, X, X, X, _, _, X, X, _, _, X, X, _, _, _, _, X, X, _, _, X, _, X, _, X, X, X, _, X, X, X, _, _, X, _, _, X, _, _, X, _, _, _, _, X, X, X, _, _, X, _, _, _, _, _],
[_, _, _, _, X, _, X, _, X, _, _, _, X, _, X, _, X, _, X, _, _, _, _, X, _, _, X, _, _, _, X, _, _, _, _, _, X, _, _, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, _, X, _, X, _, X, _, _, _, X, _, _, _, X, _, X, _, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, _, _, X, _, _, _, _, _, _, X, _, X, _, X, _, X, _, _, X, _, _, _, X, _, _, X, _, X, _, X, X, _, X, _, _, _, _, _, X, _, _, X, _, X, _, _, _, _],
[_, _, _, _, X, X, _, _, X, _, _, _, X, X, X, _, _, X, _, _, _, _, _, X, _, _, X, _, _, _, X, X, _, _, _, _, X, _, _, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, _, X, X, _, _, X, X, _, _, X, X, _, _, X, X, _, _, _, _, _, X, X, _, _, X, X, _, _, X, X, _, _, _, X, _, _, _, X, _, _, _, _, _, X, X, _, _, X, _, X, _, _, X, _, _, _, X, _, _, X, _, X, _, X, X, X, X, _, _, _, _, _, X, _, _, X, _, X, _, _, _, _],
[_, _, _, _, X, _, _, _, X, _, _, _, X, _, X, _, _, X, _, _, _, _, _, X, _, _, X, _, _, _, X, _, _, _, _, _, X, _, _, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, _, X, _, X, _, X, _, _, _, X, _, _, _, X, _, X, _, _, _, _, X, _, _, _, X, _, X, _, X, _, _, _, _, _, X, _, _, _, X, _, _, _, _, X, _, X, _, X, _, X, _, _, X, _, _, _, X, _, _, X, _, X, _, X, _, X, X, _, _, _, _, _, X, _, _, X, _, X, _, _, _, _],
[_, _, _, _, X, _, _, _, X, X, X, _, X, _, X, _, _, X, _, _, _, _, X, X, X, _, _, X, X, _, X, X, X, _, _, _, _, X, X, _, _, X, _, _, X, X, X, _, X, X, _, _, _, _, _, X, X, _, _, X, X, X, _, X, X, X, _, X, _, X, _, _, _, _, X, _, _, _, X, _, X, _, X, X, X, _, X, X, _, _, X, X, _, _, _, _, _, X, X, _, _, X, X, X, _, _, X, _, _, _, X, _, _, _, X, _, _, X, _, _, X, _, _, _, _, _, X, _, _, _, X, _, _, _, _, _],
])
row, col = FRAME.shape
for c in range(col - row + 1):
sub = Matrix([
[FRAME[i, j + c] for j in range(5)]
for i in range(5)])
hub.display.icon(sub)
await wait(125)
#make the "bubbles" rise up
#This is sh**** a** crap code from hell. Constantly check that we're still in gameState 0 so an error isn't thrown when the game starts.
async def attractLights():
while True:
if gameState == 0:
await firstSensor.light.on(Color.BLUE)
await wait(250)
if gameState == 0:
await secondSensor.light.on(Color.BLUE)
await wait(250)
if gameState == 0:
await thirdSensor.light.on(Color.BLUE)
await firstSensor.light.off()
await wait(250)
if gameState == 0:
await fourthSensor.light.on(Color.BLUE)
await secondSensor.light.off()
await wait(250)
if gameState == 0:
await thirdSensor.light.off()
await wait(250)
if gameState == 0:
await fourthSensor.light.off()
await wait(5000)
#wait to recieve data from ICB Hub 2 before beginning game
async def awaitStart():
global gameState
while gameState == 0:
data = hub.ble.observe(253)
if data is not None:
if data == 1:
hub.light.on(Color.GREEN)
card = 1
print ("green card inserted")
elif data == 2:
card = 2
hub.light.on(Color.WHITE)
print ("white card inserted")
elif data == 3:
card = 3
hub.light.on(Color.YELLOW)
print ("yellow card inserted")
elif data == 4:
card = 4
hub.light.on(Color.RED)
print ("red card inserted")
else:
print("ERROR")
await hub.speaker.beep(400, 100)
await hub.speaker.beep(450, 100)
#This is dumb. If I have the light for the firstSensor or controller turn off here, it crashes.
gameState = 1
await secondSensor.light.off()
await thirdSensor.light.off()
await fourthSensor.light.off()
else:
await wait(20)
async def attractMode():
await multitask(displayAttract(), awaitStart(), attractLights(), race=True)
while gameState == 0:
hub.ble.broadcast(1)
run_task (attractMode())
#reset game, have bar pick up ball, play song, and flash correct hole
async def firstReset():
await multitask(resetBeam(), firstLight(), playSong())
async def secondReset():
await multitask(resetBeam(), secondLight(), playSong())
async def thirdReset():
await multitask(resetBeam(), thirdLight(), playSong())
async def fourthReset():
await multitask(resetBeam(), fourthLight(), playSong())
run_task(firstReset())
#beam controls
async def beam():
while True:
pressed = controller.buttons.pressed()
if Button.RIGHT_PLUS in pressed and RMotor.angle() < -80:
RMotor.run(300)
elif Button.RIGHT_MINUS in pressed and RMotor.angle() > -1300:
RMotor.run(-300)
else:
RMotor.hold()
if Button.LEFT_PLUS in pressed and LMotor.angle() < 1100:
LMotor.run(-300)
elif Button.LEFT_MINUS in pressed and LMotor.angle() > 60:
LMotor.run(300)
else:
LMotor.hold()
await wait(20)
#tilt
async def tilt():
global tilted
while hub.imu.angular_velocity(Axis.Y) < 10:
await wait(20)
print("TILT")
LMotor.hold()
RMotor.hold()
tilted = True
#display - show ball number and timer while playing
async def display():
global timer
timer = 20
updateDisplay = True
while True:
if updateDisplay:
hub.display.number(timer)
await wait(2000)
if updateDisplay:
if balls == 1:
hub.display.icon(one)
elif balls == 2:
hub.display.icon(two)
elif balls == 3:
hub.display.icon(three)
await wait(2000)
timer -= 1
#OOPS and TILT
async def displayOops():
global updateDisplay
global tilted
updateDisplay = False
if tilted:
await firstSensor.light.on(Color.RED)
await secondSensor.light.on(Color.RED)
await thirdSensor.light.on(Color.RED)
await fourthSensor.light.on(Color.RED)
X = 100
_ = 0
FRAME = Matrix([
[_, _, _, _, X, X, X, _, X, X, X, _, X, _, _, _, X, X, X, _, _, _, _, _],
[_, _, _, _, _, X, _, _, _, X, _, _, X, _, _, _, _, X, _, _, _, _, _, _],
[_, _, _, _, _, X, _, _, _, X, _, _, X, _, _, _, _, X, _, _, _, _, _, _],
[_, _, _, _, _, X, _, _, _, X, _, _, X, _, _, _, _, X, _, _, _, _, _, _],
[_, _, _, _, _, X, _, _, X, X, X, _, X, X, X, _, _, X, _, _, _, _, _, _],
])
row, col = FRAME.shape
for c in range(col - row + 1):
sub = Matrix([
[FRAME[i, j + c] for j in range(5)]
for i in range(5)])
hub.display.icon(sub)
await wait(125)
tilted = False
await firstSensor.light.off()
await secondSensor.light.off()
await thirdSensor.light.off()
await fourthSensor.light.off()
await controller.light.off()
else:
X = 100
_ = 0
FRAME = Matrix([
[_, _, _, _, _, X, _, _, _, X, _, _, X, X, _, _, _, X, X, _, _, _, _, _],
[_, _, _, _, X, _, X, _, X, _, X, _, X, _, X, _, X, _, _, _, _, _, _, _],
[_, _, _, _, X, _, X, _, X, _, X, _, X, X, _, _, _, X, _, _, _, _, _, _],
[_, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, _, _, X, _, _, _, _, _],
[_, _, _, _, _, X, _, _, _, X, _, _, X, _, _, _, X, X, _, _, _, _, _, _],
])
row, col = FRAME.shape
for c in range(col - row + 1):
sub = Matrix([
[FRAME[i, j + c] for j in range(5)]
for i in range(5)])
hub.display.icon(sub)
await wait(110)
async def drainSong():
if tilted:
await hub.speaker.beep(200, 1000)
else:
await hub.speaker.beep(200,150)
await hub.speaker.beep(190,150)
await hub.speaker.beep(180,150)
await hub.speaker.beep(170,150)
await hub.speaker.beep(160,150)
await hub.speaker.beep(150,150)
await hub.speaker.beep(140,150)
await hub.speaker.beep(130,150)
await hub.speaker.beep(120,150)
await hub.speaker.beep(110,150)
for x in range(3):
await wait(25)
await hub.speaker.beep(110,100)
await wait(1000)
async def drain():
await multitask(displayOops(), drainSong())
#If the ball goes into the wrong color, or game is tilted
async def miss():
global balls
global gameState
global updateDisplay
global timer
while True:
if updateDisplay:
await hub.ble.broadcast(2)
missed = hub.ble.observe(253)
if tilted or missed:
balls += 1
await drain()
print(balls)
if balls == 4:
gameState = 8
elif gameState == 1:
await firstReset()
elif gameState == 2:
await secondReset()
elif gameState == 3:
await thirdReset()
elif gameState == 4:
await fourthReset()
break
else:
await wait(20)
#first target
async def firstTarget():
global gameState
hub.light.off()
while await firstSensor.reflection() <= 19:
await wait(10)
print("First target hit")
await firstSensor.light.off()
LMotor.hold()
RMotor.hold()
await addScore()
gameState = 2
await secondReset()
#second target
async def secondTarget():
global gameState
while await secondSensor.reflection() <= 19:
await wait(10)
print("Second target hit")
await secondSensor.light.off()
LMotor.hold()
RMotor.hold()
await addScore()
gameState = 3
await thirdReset()
#third target
async def thirdTarget():
global gameState
while await thirdSensor.reflection() <= 19:
await wait(10)
print("Third target hit")
await thirdSensor.light.off()
LMotor.hold()
RMotor.hold()
await addScore()
gameState = 4
await fourthReset()
#Fourth target
async def fourthTarget():
global gameState
while await fourthSensor.reflection() <= 18:
await wait(10)
print("Fourth target hit")
LMotor.hold()
RMotor.hold()
await addScore()
gameState = 5
#Add score
async def addScore():
global score
global timer
global updateDisplay
updateDisplay = False
await hub.speaker.play_notes(["C2/1_","C2/4_","C3/6_","C4/6_","C5/6_","C6/6_"],tempo=300)
await wait(100)
while timer != 0:
timer -= 1
score += 1
hub.display.number(score)
await hub.speaker.beep(160,100)
await wait(100)
await wait(500)
async def playFirst():
await multitask(miss(), beam(), firstTarget(), display(), tilt(), race=True)
while gameState == 1:
run_task (playFirst())
#second target
async def playSecond():
await multitask(miss(), beam(), secondTarget(), display(), tilt(), race=True)
while gameState == 2:
run_task (playSecond())
#third target
async def playThird():
await multitask(miss(), beam(), thirdTarget(), display(), tilt(), race=True)
while gameState == 3:
run_task (playThird())
#fourth target
async def playFourth():
await multitask(miss(), beam(), fourthTarget(), display(), tilt(), race=True)
while gameState == 4:
run_task (playFourth())
#WINNER
#bubbles rise, then flash lights
async def flashLights():
while True:
await firstSensor.light.on(Color.BLUE)
await wait(250)
await secondSensor.light.on(Color.BLUE)
await wait(250)
await thirdSensor.light.on(Color.BLUE)
await firstSensor.light.off()
await wait(250)
await fourthSensor.light.on(Color.BLUE)
await secondSensor.light.off()
await wait(250)
await thirdSensor.light.off()
await wait(250)
await fourthSensor.light.off()
for i in range(5):
await firstSensor.light.on(Color.BLUE)
await secondSensor.light.on(Color.BLUE)
await thirdSensor.light.on(Color.BLUE)
await fourthSensor.light.on(Color.BLUE)
await controller.light.on(Color.BLUE)
await wait(250)
await firstSensor.light.off()
await secondSensor.light.off()
await thirdSensor.light.off()
await fourthSensor.light.off()
await controller.light.off()
await wait(250)
async def winSong():
t = 40
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(5):
await hub.speaker.beep(131,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(4):
await hub.speaker.beep(131,200)
await wait(t)
await hub.speaker.beep(262,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(5):
await hub.speaker.beep(262,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(4):
await hub.speaker.beep(262,200)
await wait(t)
await hub.speaker.beep(131,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(6):
await hub.speaker.beep(131,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(87,200)
await wait(t)
for i in range(5):
await hub.speaker.beep(131,200)
await wait(t)
async def displayWin():
hub.display.icon(star)
await wait(10000)
async def playWin():
await multitask(flashLights(), displayWin(), winSong(), race=True)
while gameState == 5:
run_task (playWin())
wait(1000)
gameState = 8
#Game Over
async def displayGameOver():
print("gameover")
X = 100
_ = 0
FRAME = Matrix([
[_, _, _, _, _, X, X, _, _, _, X, _, _, X, _, _, _, X, _, X, X, X, _, _, _, _, X, _, _, X, _, X, _, X, X, X, _, X, X, _, _, _, _, X, _, X, _, _, X, _, _, X, _, X, _, X, X, _, _, _, _, _, X, X, _, _, X, X, _, _, X, _, _, X, X, _, _, X, X, X, _, _, _, _, _, _, _],
[_, _, _, _, X, _, _, _, _, X, _, X, _, X, X, _, X, X, _, X, _, _, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, X, _, X, _, X, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, _, _, X, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, _, _, _, _],
[_, _, _, _, X, _, X, X, _, X, X, X, _, X, _, X, _, X, _, X, X, _, _, _, _, X, _, X, _, X, _, X, _, X, X, _, _, X, X, _, _, _, _, _, X, _, _, X, _, X, _, X, _, X, _, X, X, _, _, _, _, _, X, _, _, X, _, _, _, X, _, X, _, X, X, _, _, X, X, _, _, _, _, _, _, _, _],
[_, _, _, _, X, _, _, X, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, X, _, _, _, _, X, _, _, X, _, X, _, X, _, X, _, X, _, X, _, _, _, _, _, X, _, X, _, _, _, X, _, X, _, X, _, X, _, X, _, _, _, X, _, _, _, _, _],
[_, _, _, _, _, X, X, _, _, X, _, X, _, X, _, _, _, X, _, X, X, X, _, _, _, _, X, _, _, _, X, _, _, X, X, X, _, X, _, X, _, _, _, _, X, _, _, _, X, _, _, X, X, X, _, X, _, X, _, _, _, X, X, _, _, _, X, X, _, _, X, _, _, X, _, X, _, X, X, X, _, _, _, _, _, _, _],
])
row, col = FRAME.shape
for c in range(col - row + 1):
sub = Matrix([
[FRAME[i, j + c] for j in range(5)]
for i in range(5)])
hub.display.icon(sub)
await wait(110)
hub.display.number(score)
await wait(1000)
hub.display.off()
async def gameOverSong():
t = 80
for i in range(2):
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(70,200)
await hub.speaker.beep(75,200)
await wait(t)
await hub.speaker.beep(80,200)
await hub.speaker.beep(85,200)
await wait(t)
await hub.speaker.beep(80,200)
await hub.speaker.beep(75,200)
await wait(t)
await hub.speaker.beep(70,200)
for i in range(2):
await hub.speaker.beep(85,200)
await wait(t)
await hub.speaker.beep(90,200)
await hub.speaker.beep(95,200)
await wait(t)
await hub.speaker.beep(100,200)
await hub.speaker.beep(105,200)
await wait(t)
await hub.speaker.beep(100,200)
await hub.speaker.beep(95,200)
await wait(t)
await hub.speaker.beep(90,200)
await hub.speaker.beep(65,200)
await wait(t)
await hub.speaker.beep(70,200)
await hub.speaker.beep(75,200)
await wait(t)
await hub.speaker.beep(80,200)
await hub.speaker.beep(85,200)
await wait(t)
await hub.speaker.beep(80,200)
await hub.speaker.beep(75,200)
await wait(t)
await hub.speaker.beep(70,200)
await hub.speaker.beep(65,200)
async def playGameOver():
await multitask(displayGameOver(), gameOverSong())
while gameState == 8:
hub.ble.broadcast(None)
run_task(playGameOver())
wait (1000)
gameState = 0
print("the end") |
Beta Was this translation helpful? Give feedback.
All reactions
-
Any ideas? I've tried having firstTarget check that it's still in gameState 1 and having the miss loop change gameState to something else, but for some reason it's still crashing there. |
Beta Was this translation helpful? Give feedback.
Oop, didn't notice the
run_task()
inattractLights
. That is the actual source of the problem. It needs to be replaced withawait
.Although
subtask()
currently isn't awaiting anything itself, so it could actually be turned onto a regular fucntion.