psychopy.org | Reference | Downloads | Github

Clock face stimuli while a routine loop is running and a feedback sound

Hi

For my research i need to create an experiment that evaluates executive function under stress.
I have chosen the ANT experiment as my template and i want to add to the trial part

  1. a clock face stimuli on the side of the screen while a routine loop is running
  2. a feedback sound that buzzes every time the answer is incorrect.

I have searched the forum for hours and tried various codes in my coder ( clockface.py i took from coder demo) but for some reason nothing worked.
i think the basic knowledge that i am missing is how to convert a script i found into a functioning code in the builder.
i have attached 2 screen shots that show how:

  1. i added a code that calls if the answer is incorrect apply the buzzer- it completely ingnors it
    2.added a countdown stimuli in the trial block- causes the experiment not to run at all

i wish i had a good tutorial on how to put a code from the coder into the builder- i did not see any answers on YouTube/forum

Thank you so much
Chaya


In general, Builder -> Coder is a one way process. The way it works is that the components in Builder know how to write themselves as code, but Python code can be anything, not just components, so you can’t take any Python script and create components from it. However, if you have one particular bit of code (e.g. to do a calculation or conversion) then you can add it in a Code component.

What I would do is take all the code in that while not event.getKes() loop and put it in a Code component’s Each Frame tab, then replace while with if - this means that the code will run each frame, if a key hasn’t been pressed. The rest of the code does things like setting up a window and creating stimuli - much of which is already done for you in Builder, so creates an error because it tries to do it twice.

For the code to work, you need to have the following variables defined:
hour
minute
second
handVerts
win
clock

clock and win are already defined by default when using Builder, so you don’t need to worry about that.

handVerts can be defined by copying the handVerts = ... line into the Begin Experiment tab of a Code Component. The rest can be created using Polygon components - just copy all the values in the brackets into the corresponding boxes, and ensure the name of each is the same as in the code.

1 Like

Thank you so much!

I tried doing that and the experiment wont run.

  • in the Before experiment tab i imported division, win and time
  • in the Begin experiment i defined the variables
  • in the Each frame i added the if statement
if not event.getKeys():
    t = time.localtime()

    minPos = numpy.floor(t[4]) * 360 / 60  # NB floor will round down
    minute.ori = minPos
    minute.draw()

    hourPos = (t[3]) * 360 / 12  # this one can be smooth
    hour.ori = hourPos
    hour.draw()

    secPos = numpy.floor(t[5]) * 360 / 60  # NB floor will round down
    second.ori = secPos
    second.draw()

    win.flip()
    event.clearEvents('mouse')  # only really needed for pygame windows

win.close()
core.quit()
  • .
    I was wondering maybe this code shouldn’t run the same routine as all my feedback and have its own routine in the begging of the practice loop?
    But I want the clock face stimuli to be presented on screen during the task.

Are you getting any error messages? I notice you’re using 2020.2.6, we’ve fixed a bug since then which was preventing error messages from appearing if the experiment was opened directly via a shortcut rather than by opening PsychoPy and then using the Open dialog, so if you’re not getting any error messages try closing PsychoPy and reopening that way.

This thread prompted me to recreate the clockFace demo in Builder, which will now be in the next major release, so you can also use this demo as a basis if you like:
clockFace.psyexp (11.6 KB)

Thank you! i am happy that my thread will help others.

I did not get an error message . I also did not notice that my version is not the most updated one.
ill try opening PsychoPy not using the shortcut

Hey

its me again. i am trying to add my clock face stimuli during the trial routine- meaning the tester will see a clock on the top screen throughout the stroop trial.
The first think i did was to use the clockface as a routine. i changed the anchor code to each frame tab and not begin routine tab , but the clock apeared after i clicked the correct answer in full screen.
So i though of adding all the clockface component into the trial routine and not as a routine by itself.
I did not work. my experiment stopped and exited without an error popping

what i am asking is. how can i changes this clockface to appear in the trial screen as part of the component and not as a standalone clock screen.

Thank you so much

Chaya

I don’t think the problem is that the components are in your trial routine so much as that they have a different name there - the code in anchor sets the vertices of each of the clock hands so that they rotate around the base rather than their center, but it does so by referring to the hand polygons by name. So you need to change this bit:

sizes = {
    hour: (0.04, 0.3),
    minute: (0.02, 0.4),
    second: (0.005, 0.4)
}

for obj in [hour, minute, second]:

to point to your actual polygon names:

sizes = {
    hour_2: (0.04, 0.3),
    minute_2: (0.02, 0.4),
    second_2: (0.005, 0.4)
}

for obj in [hour_2, minute_2, second_2]:

If the name of the Variable component times has also changed then you will need to replace times in any component properties with times_2 as well.

Thank you so much ! i figures it out yesterday and it works! i just need to move it to the side of the screen and not the middle.
ill try doing it in each variant

thanks again

Hi its me again :slight_smile:
i am trying to increase the pace of the watch - meaning i want it to show a 30 sec time frame instead of the standatd hr, min,sec .
do i need to change it in the anchor code? or in the times?

thanks!