Running only one row of condition file online

URL of experiment: Sign in · GitLab

Description of the problem: I’m trying to run a loop that will only execute one row (out of 8) of an excel file. This works in python, but not online. The loop works fine online if I leave the “Selected rows” field blank, though. When I try selecting a specific row (say 0), and run it online, the variable are undefined. This (below) is how I set the loop up in builder.

image

From looking at the code (below), looks like the key might be setting up the triallist parameter to select a specific row using importConditions using a code component.

var consent_loop;
var currentLoop;
function consent_loopLoopBegin(thisScheduler) {
  // set up handler to look after randomisation of conditions etc
  consent_loop = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 0.125, method: TrialHandler.Method.RANDOM,
    extraInfo: expInfo, originPath: undefined,
    trialList: (((((('dom' + dom) + 'fin') + fin) + 'habf') + habf) + '.xlsx'),
    seed: undefined, name: 'consent_loop'
  });
  psychoJS.experiment.addLoop(consent_loop); // add the loop to the experiment
  currentLoop = consent_loop;  // we're now the current loop

I tried setting up selec = importConditions(psychoJS.ServerManager, (((((('dom' + dom) + 'fin') + fin) + 'habf') + habf) + '.xlsx'),0) in a code component in the “begin experiment” tab, and then using it as the trialList argument for consent_loop, but this wouldn’t even let the study start running.

Ideas? Thanks!

I have the same problem. @amazar - did you find any solution? My related post is my problem 1 in this post: https://discourse.psychopy.org/t/error-in-reading-nested-loop-excel-file-for-online-version/14254/2

Found a solution that works for me for the online and offline version. Paste in Selected rows “1:2”, then the second row is always selected - should also work with “0:1”, but have not tested.

Very interesting, thanks! I just ended up setting up variables using a custom code component in JS (which is more elegant than endless excel tables anyway):

function randArr(arr) {
    return arr[Math.floor(Math.random() * arr.length)];
}

varArr = ["level1","level2"];

var = randArr(varArr);

if (varArr === "level1") {
   // Set level 1 trials
} else {
  // Set level 2 trials
}

This would be in the “begin experiment” tab.

1 Like

0:1 is the correct way to select row 0

1 Like