psychopy.org | Reference | Downloads | Github

Psychopy to Javascript code

OS : Windows 10
PsychoPy version: v3.2.4

What are you trying to achieve?: I am trying to run my experiment on Pavlovia but I need to translate my custom code from Py to JS. I am not familiar enough with either one to be able to translate it. Could someone please help me translate this to Java Script please, thank you!
if(“backspace” in code_resp.keys):
code_resp.keys.remove (“backspace”)

if(len(code_resp.keys) > 0):
    code_resp.keys.pop()

elif(“return” in code_resp.keys):
code_resp.keys.remove (“return”)

screen_text = ''.join(code_resp.keys)
thisExp.addData("ppt_code", screen_text)


continueRoutine = False

screen_text = ‘’.join(code_resp.keys)

This is the second custom code I have:
if loop.thisTrialN not in [53,106,159,212]:
continueRoutine=False

I’ve used the following in a free recall task.

if cursorCounter >= 30:
    if cursorVariable=='|':
        cursorVariable='.'
    else:
        cursorVariable='|'
    cursorCounter=0
cursorCounter+=1

if subject_response_finished:
    continueRoutine=False
    
keys = event.getKeys()
if len(keys):
    if 'escape' in keys:
        core.quit()
    elif 'backspace' in keys:
        if len(recallitems[thisitem])>0:
            recallitems[thisitem] = recallitems[thisitem][:-1]
        else:
            recallitems[thisitem-1]=recallitems[thisitem-1]+recallitems[thisitem]
            for Idx in range(thisitem,6):
                recallitems[Idx] = recallitems[Idx+1]
            recallitems[6]=''
            thisitem=thisitem-1
    elif 'delete' in keys:
        recallitems[thisitem] = recallitems[thisitem][:-1]
    elif 'space' in keys:
        subject_response_finished=True
    elif 'return' in keys and thisitem<6:
        thisitem=thisitem+1
        for Idx in range(6,thisitem,-1):
            recallitems[Idx] = recallitems[Idx-1]
        recallitems[thisitem] = ''
    elif 'up' in keys and thisitem>0:
        thisitem=thisitem-1
    elif 'down' in keys and thisitem<6:
        thisitem=thisitem+1
    elif 'a' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'A'
    elif 'b' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'B'
    elif 'c' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'C'
    elif 'd' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'D'
    elif 'e' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'E'
    elif 'f' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'F'
    elif 'g' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'G'
    elif 'h' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'H'
    elif 'i' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'I'
    elif 'j' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'J'
    elif 'k' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'K'
    elif 'l' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'L'
    elif 'm' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'M'
    elif 'n' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'N'
    elif 'o' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'O'
    elif 'p' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'P'
    elif 'q' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'Q'
    elif 'r' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'R'
    elif 's' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'S'
    elif 't' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'T'
    elif 'u' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'U'
    elif 'v' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'V'
    elif 'w' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'W'
    elif 'x' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'X'
    elif 'y' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'Y'
    elif 'z' in keys:
        recallitems[thisitem] = recallitems[thisitem]+'Z'
    else:
        pass

newText=''
for Idx in range(7):
    if numberText==1:
        newText = newText+str(nWords-6+Idx)+') '
    newText = newText+recallitems[Idx]
    if Idx == thisitem:
        newText = newText+cursorVariable
    newText = newText + '\n'
newText=newText + '______________'
if newText != displayText:
    displayText=newText
    recall_text.setText(displayText)

Hello,

Thank you for your reply! Unfortunately I am not sure if this is similar enough to work for my experiment. Do you know how to translate the following to javascript?
It is custom code to ensure there are breaks for participants at specific times in the trial blocks.

if loop.thisTrialN not in [53,106,159,212]:
continueRoutine=False

As per my crib sheet all loops need to be referred to as trials.