psychopy.org | Reference | Downloads | Github

A self-paced pause within a loop

Hello,

I am a beginner and have little knowledge about coding.

I am now building a lexical decision task with randomized prime-target pairs presented. There are a total of 80 pairs and I would like to insert a self-paced pause that people can pause whenever they want.

If that is not possible, I would like to insert a pause after the completion of 40 pairs without interrupting the loop. What can I do with that? Thanks!

It’s hard to give advice without some sense of what the program looks like now. How are you getting their responses? How is the loop put together?

the loop is presented in the sequence of

prime object 1 --> prime object 2 --> respond by pressing ‘a’ or ‘l’, and continue to the other pair

Oh, I see, this was constructed using the builder. I’m not as familiar with the builder, but you may wish to re-tag this post as “Builder” and see if anyone knows how to add this kind of functionality to an experiment without adding code.

I’m not sure that you’d be able to add that kind of functionality without adding code.

The best idea is probably to add a code component to the builder within the loop. Jonathan, do you have any idea about a code snippet that would cause the experiment to pause (and unpause) at will?

I don’t have the solution, but I’d like to know the answer too as I’m hoping to add something like this to a future experiment of mine!

OK, I poked around for 5 minutes and figured out a quick and easy solution. I never use the builder, so kudos to its design that I was able to work this out so quickly.

Add a “code” object to your trial (you may need to add it to both trials if you want them to be able to pause any time). In it, select the “every frame” tab. Use the following code:

keys = event.getKeys()

if 'p' in keys:
    event.waitKeys()

You can replace ‘p’ with whatever you want your pause key to be. Basically, whenever someone presses ‘p’ on a trial that has this code, the experiment will simply stop until they press another key.

If you want to get fancier and make the screen go blank while it is paused, you can do this:

keys = event.getKeys()

if 'p' in keys:
    for thisComponent in trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    win.flip()
    event.waitKeys()
    for thisComponent in trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(True)

This tells it to turn off auto-draw for everything in the experiment, blank the screen, then turn auto-draw back on when it’s done.

Note that this won’t record any information about how long they paused, or in fact give you any information in your data file that they paused at all. That would require some more complex code, but if you just want to be able to pause, this will get the job done.

1 Like

Very helpful, thank you!

Hello! I am totally a green hand in coding, and recently working on conducting an experiment, including lexical decision task. I tried to enter stimulus (i.e. primes and target) into excel, and upload it in builder. But It wouldn’t work. Can you give me some advice on what I should do with coding? Thanking you in anticipation.

  • Please make a new topic for your issue.
  • To get help, we need a specific and detailed description of what you did and what went wrong. Please think "could a person give me a useful answer to my problem, given nothing other than the information I have provided them? "
  • Maybe you don’t need any coding at all: let’s not jump the gun, and instead just start with getting the basic of your task running.

Thank you for your reply Michael. Basically I want to build a lexical decision task, where participants would be presented with the first few words of one idiom, and they can set their own reading pace and hit the spacebar, after which the final word of the idiom would show. At this time, they are asked to respond by pressing one of the two specific keys to judge whether the final word is a real English word or just fake word. They will be around 60 items in total. I don’t know what format I should follow to create the excel. And do I need to learning coding and write codes in the coder? Or is there any specific trial type for me to follow? Thanking you in anticipating.