#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# Programming coroutines

Dear OpenSesmae users,

I'm trying to figure out how to use coroutine using inline scripts and I'm having no success yet.

I'm trying to create an experiment in which participants need to move clock hands (on canvas) with right and left keyboard keys and to stop the procedure by pressing ENTER.

Unfortunately, I couldn't understand whether I need to create the inline scripts of the canvas and the keyboards within the inline_script of the coroutine and how.

I'll be grateful for any type of help.

• Hi,

I wouldn't do this with coroutines. It's probably possible, but more trouble than it's worth. Instead, I would write a simple `inline_script`. The script below should get you started. It shows a simple clock with one hand, which you can adjust until you press enter. Do you get the logic? It's not that difficult, really.

``````rho = 100 # Length of the clock
phi = -90 # Vertical ration

clock = canvas()
my_keyboard = keyboard()

# Loop until return breaks
while True:
# Draw a clock
x, y = xy_from_polar(rho, phi)
clock.clear()
clock.circle(0, 0, rho)
clock.line(0, 0, x, y)
clock.show()
# Poll the keyboard
key, time = my_keyboard.get_key()
print(key)
if key == 'left':
phi -= 1
elif key == 'right':
phi += 1
elif key == 'return':
break
``````

Cheers!
Sebastiaan

There's much bigger issues in the world, I know. But I first have to take care of the world I know.
cogsci.nl/smathot

• Thank you so much!
You guys are so helpful and kind!