Change the experiment directly in JS code from Pavlovia?

Hi,

URL of experiment: https://run.pavlovia.org/APPL/gender_perception_condition_3_feminine_female_left/html

Description of the problem: I have two blocks, i.e., normal and whisper. The way I have set up is that the normal block will always be the first block and followed by the whispered block. However, is it possible to directly change this in the JS code where the whispered block comes first? The order of block is controlled by the most outer loop, called block_order. And the csv file is called order.csv in the resource folder. Here is what is looks like:

n_voiced, n_whisper
1, 0
0, 1

I just need to switch to

n_voiced, n_whisper
0, 1
1, 0

I know that I could totally change this locally and then re-sync with the project. However, I have had many troubles doing this since the Slider style is changed drastically in this newest PsychoPy version and the experiment was built under a previous version.

I would greatly appreciate any help here.

Might the outer actually be called order_select?

Hi @thomas_pronk,

yea you are right. That was a typo. Any thoughts on how should I solve the question?

Yes I do actually :). I think changing orders in this part might achieve what you want.

  // Schedule all the trials in the trialList:
  for (const thisOrder_select of order_select) {
    const snapshot = order_select.getSnapshot();
    thisScheduler.add(importConditions(snapshot));
    const vd_blockLoopScheduler = new Scheduler(psychoJS);
    thisScheduler.add(vd_blockLoopBegin, vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopEnd);
    const whisper_blockLoopScheduler = new Scheduler(psychoJS);
    thisScheduler.add(whisper_blockLoopBegin, whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopEnd);
    thisScheduler.add(endLoopIteration(thisScheduler, snapshot));
  }
1 Like

@thomas_pronk.
Thanks! However, i encountered the following error: that order_select is not iterable. What does this mean?

How did you change it?

I replaced the old code with the one you gave me. Here is the screenshot

@thomas_pronk i might have misunderstood your suggestion. I copied and pasted in the wrong section in the above screenshot. I reverted the change and change the order in the correct code section. However, when I ran the experiment, it is still running the normal block first.

The code I quoted in my earlier posts was copy-pasted from the JS I found in your experiment. Note though that I’m not diving in the details of your experiment, but I’ll make a suggestion below. Whatever you do, be sure to test it carefully.

You could try replacing the code I quoted by the code below:

  // Schedule all the trials in the trialList:
  for (const thisOrder_select of order_select) {
    const snapshot = order_select.getSnapshot();
    thisScheduler.add(importConditions(snapshot));
    const whisper_blockLoopScheduler = new Scheduler(psychoJS);
    thisScheduler.add(whisper_blockLoopBegin, whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopEnd);
    const vd_blockLoopScheduler = new Scheduler(psychoJS);
    thisScheduler.add(vd_blockLoopBegin, vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopEnd);
    thisScheduler.add(endLoopIteration(thisScheduler, snapshot));
  }

Yea i have made this change in both the Js file (one is legacy-broswer.js). It is still running the normal block first unfortunately :frowning: Are changes made in the JS code directly synced to the experiment on Pavlovia?

Nope, they are not. You could check that by looking in the GitLab repo. Maybe manually update it via GitLab?

this is actually what I did. I made all the changes directly in GitLab. But, those changes were not reflected when I run the experiment.

Maybe clear your cache? Here are two tricks for that:

  1. Add ?blabla to the URL to your experiment; your browser thinks it’s a new page then
  2. Or… do “view source”, click the JS file, when you see the JS in your browser, refresh, then restart experiment

tried both and did not work :frowning: One thing that I noticed is that on the experiment page, the update date is not reflected correctly and i think this may be the problem.

Actually, this has been a huge problem for me when syncing experiments. Oftentimes, the changes really are not updated and I had to deleted the entire experiment and reupload

Hmmm… I’d like to take look if that’s OK. Could you give me access to the gitlab repo? My username is tpronk. Here are some pointers on how to give me access. https://www.psychopy.org/online/fromBuilder.html#posting-the-issue-on-the-forum

definitely! I really appreciate your help here. I have added you to the project. Please let me know if it does not work. I am really new to this Git world.

Hi @thomas_pronk,
Just want to check in to see if the access works.

Hey again,

I got access. The trick below worked for me; first I still saw the old order in your JS, but after refreshing it looked like this.

    thisScheduler.add(whisper_blockLoopBegin, whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopScheduler);
    thisScheduler.add(whisper_blockLoopEnd);
    const vd_blockLoopScheduler = new Scheduler(psychoJS);
    thisScheduler.add(vd_blockLoopBegin, vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopScheduler);
    thisScheduler.add(vd_blockLoopEnd);

Here is a direct link to the source

1 Like

YAY!! thanks so much. now the experiment works to the way I wanted. If you don’t mind me asking one more clarification, when you said, view source, you meant View Page Source in the experiment page right?
The direct link to the source you have does not work for me.

1 Like

Nice it works! Here a hopefully clearer explanation of the steps:

  1. Start your experiment
  2. View Page Source
  3. In the source, click the JS experiment (look for <script type='module' src='./gender_perception_condition_3_feminine_female_left.js'></script>)
  4. Now you’ll see the JS of your experiment. Refresh
1 Like