JS Conversion for Builder Experiment

Hello,

I have created a boundary extension paradigm in the Builder in which participants can zoom in and out of an image. In order to create the zoom I used a code snippet to zoom a set amount of pixels.

Python Code.

if response_image.status == STARTED:
      key = event.getKeys() # get just the last key
      if len(key) > 0:
          if key[0] == 'left':     # shrink the image:
              response_image.size += (-10,-10)
          elif key[0] == 'right':     # grow the image:
              response_image.size += (10,10)
          elif key[0] == 'space':     # store the size in the data file and end the routine. For ease of use, we just     # store one component of the size (i.e. the x component).
              thisExp.addData('chosen_size', response_image.size)
              thisExp.addData('RT', t)
              continueRoutine = False
          elif key[0] == 'q':     # we need to handle this manually now for their routine:
              win.close()
              core.quit()

  keys = event.getKeys(keyList = ['q'])
  if 'q' in keys:
      win.close()
      core.quit()

  event.clearEvents(eventType = 'keyboard')

I am trying to convert this to JS to run on Pavlovia and have been testing my JS code in the builder (I haven’t uploaded it to Pavlovia yet). Here is the code.

if (psychoJS.response_image.status == STARTED){
    let theseKeys = psychoJS.eventManager.getKeys({keyList:['left','right','space','q']});
    if(theseKeys.length > 0){
      if(theseKeys() == 'left') {
        psychoJS.response_image.size = psychoJS.response_image.size + 100;
      }
      else if(theseKeys() == 'right') {
        psychoJS.response_image.size = psychoJS.response_image.size +100;
      }
      else if (theseKeys() == 'space') {
        psychoJS.experiment.addData('chosen_size', response_image.size);
        psychoJS.experiment.addData('RT', t);
        continueRoutine = False;
      }
      else(theseKeys() == 'q'){
                win.close();
                core.quit();
          }
}
}

let theseKeys = psychoJS.eventManager.getKeys({keyList:['q']});
if (theseKeys.indexOf('q')) {
    win.close()
    core.quit()
  }

event.clearEvents(eventType = 'keyboard')

My questions are…

  1. Is there anything glaringly wrong with the JS code?
  2. Do I need to actually run the experiment on Pavlovia to trial the JS code, and not in the builder locally?

I hope this all makes sense, as you can probably tell Im new to this. Thank you in advance for your help!!

Alex

Yes, I’m afraid you currently need to push the study online to test it. We are working on a local-debug method for PsychoPy v3.3

1 Like

Thanks Jon. I guessed that may be the case!