psychopy.org | Reference | Downloads | Github

Unlimited Responses In 30 s

I’m trying to create a program where every time a target stimulus is clicked on a reward appears briefly. The target stimulus (TS) is presented for 30 s so I would like the subject to press on the TS many times throughout the trial to get a reward. So far, using the code below, I am able to have the subject press on the TS and get one presentation of the reward. Unfortunately, after that reward disappears clicking on the TS no longer elicits it. Is there any way I can have the reward presented every time the TS is clicked on, without having to restart the trial, that way the TS will always be presented for 30 s?

while continueRoutine and routineTimer.getTime() > 0:
    # get current time
    t = trialClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *Cue1* updates
    if t >= 0.0 and Cue1.status == NOT_STARTED:
        # keep track of start time/frame for later
        Cue1.tStart = t
        Cue1.frameNStart = frameN  # exact frame index
        Cue1.setAutoDraw(True)
    frameRemains = 0.0 + 30.00- win.monitorFramePeriod * 0.75  # most of one frame period left
    if Cue1.status == STARTED and t >= frameRemains:
        Cue1.setAutoDraw(False)
    
    # *TargetStimulus* updates
    if t >= 0.0 and TargetStimulus.status == NOT_STARTED:
        # keep track of start time/frame for later
        TargetStimulus.tStart = t
        TargetStimulus.frameNStart = frameN  # exact frame index
        TargetStimulus.setAutoDraw(True)
    frameRemains = 0.0 + 30.00- win.monitorFramePeriod * 0.75  # most of one frame period left
    if TargetStimulus.status == STARTED and t >= frameRemains:
        TargetStimulus.setAutoDraw(False)
    
    # *FoodResponse* updates
    if (mouse.isPressedIn(TargetStimulus)) and FoodResponse.status == NOT_STARTED:
        # keep track of start time/frame for later
        FoodResponse.tStart = t
        FoodResponse.frameNStart = frameN  # exact frame index
        FoodResponse.setAutoDraw(True)
    if FoodResponse.status == STARTED and t >= (FoodResponse.tStart + 2):
        FoodResponse.setAutoDraw(False)

Are you doing this in builder? This looks like generated code

The basis of the experiment was created on builder but I am now looking to manipulate the source code.

It has to do with the “STARTED” status. I think what’s happening is that after the first mouse press, the status of FoodResponse becomes STARTED, and it never reverts to NOT_STARTED and so the conjunction

if (mouse.isPressedIn(TargetStimulus)) and FoodResponse.status == NOT_STARTED:

is always false.

I don’t know much about how the status system works for builder components because I don’t use the builder. The simple option, at a glance, is to get rid of the “FoodResponse.status == NOT_STARTED” in the initial conditional there, but I don’t know exactly how that will behave. In particular I have no idea if it’s going to record all of the mouse clicks properly, and it’s only going to display one reward at a time, so your participants won’t get feedback that they’re being rewarded multiple times.

I think you’ll eventually need to just custom-code something for that entire last block of code that responds to mouse clicks how you want, but not knowing how the rest of the experiment is put together or how the builder creates and uses these objects I’m afraid I can’t really offer more specific advice.

Hi Jonathan,

Getting rid of the FoodResponse.status== Not_Started: worked beautifully.

Thank you so much for your help.

No problem. Remember to mark “solved”, it helps the forum stay organized.

Where is “solved” option to mark?

Should be near like button or on the options for my reply.

Jonathan