psychopy.org | Reference | Downloads | Github

Only continue routine after 3 seconds & response slider & spacebar

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.10

I currently use the following piece of code to make sure participants first give an answer on a slider and press spacebar before they can continue. I want to add a time element to that as well.

I tried the following but it does not seem to work online.

#in python begin routine:
timer = core.CountdownTimer(3)

#in javascript begin routine:
timer =new.code.CountdownTimer(3);

and

# in python each frame:

keys = event.getKeys() 

if slider_predicts1f.getRating() is not None and 'space' in keys and timer.getTime()<0: 
    continueRoutine=False
  
# in javascript each frame: 

  var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
keys = event.getKeys();
if ((((slider_predicts1f.getRating() !== undefined) && _pj.in_es6("space", keys)) && (timer.getTime() > 0))) {
    continueRoutine = false;
}

It gives me the error:

  • TypeError: core.CountdownTimer is not a constructor

I would greatly appreciate any help with adding the 3 second ‘wait’ period before participants can continue (in addition to the spacebar and slider).


As per my crib sheet clocks need to be defined in a Both code component.

myClock = core.Clock() should be translated to myClock = new util.Clock()

However, I wouldn’t bother with a custom clock. Just add and t > 3 to your if statement instead.

t is a built in routine timer.

1 Like

Thank you so very much!

Hi,

I used both the core clock and the slider-snippet-code from your snippet document (2020.2.10), and it works fine online but gives the following error on my desktop:

File "E:\PsyTest\ACLTABv1\ACLTABv1_lastrun.py", line 1586, in <module>
    if rated == 0 and t >.1 and oefenslider_PRts1.getRating() >= 0:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'

Is it so that oefenslider_PRts1.getRating() = None (so NoneType) and this is not compatible with the >= 0?

So a solution would be to change:

if rated == 0 and t >.1 and oefenslider_PRts1.getRating() >= 0:
    rated=t
elif rated >0 and t >3 and t >rated+.1:
    continueRoutine=False

to:

if rated == 0 and t >.1 and oefenslider_PRts1.getRating() != None:
    rated=t
elif rated >0 and t >3 and t >rated+.1:
    continueRoutine=False

?

I think this is correct, but wanted to check to be sure I understand it correctly and because it is in the snippet document I am wondering if I made a mistake.

(and the code with ‘>=0’ works corrrectly online because it auto-translates correctly, but if you want it to work both on your desktop and online you have to change >=0 to != None in python and change null to undefined in javascript?)

Correct. None offline is usually undefined online.

However, you might be interested in my new interactive slider demo which ignores getRating completely.

1 Like