psychopy.org | Reference | Downloads | Github

Setting order of stimuli conditionally - link generated order to condition file

OS: MacOS 10.14.6
Platform version: 2021.1.2
URL of experiment: Pavlovia

What are you trying to achieve?:
Hi! In this social feedback task there are three conditions (3 panel members) by three conditions (panel members vary in providing negative, neutral and positive feedback). A condition excel file (referred to in trials_panel) contains the trials containing 45 rows indicating the panel member (A, B, C, 15 trials each) and whether they provide a positive, negative of neutral word.
I would like to set the stimuli in this social feedback task so that panel members are not repeated, i.e. A is followed by B or C but not A.


Description of the problem:
I have managed to code how words get selected based on whether the panel member trial is positive, negative, or neutral. I have also managed to let JS make an order of 45 ABC’s where there are no repeats. However, I do not know how to link this order to the conditions file so that it uses the order generated.

Built so far:
Using this topic: Topic - no repeats I have constructed the JS code for randomising ABC without repeat (in “begin experiment” in code component of set order routine):

datStructure = [["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"], ["A", "B", "C"]];
blockOrder = [];
for (var j = 0, _pj_a = datStructure.length; (j < _pj_a); j += 1) {
    subOrder = [];
    shuffle(datStructure[j]);
    subOrder = subOrder.concat(datStructure[j]);
    if (blockOrder.length > 0) {
        while (subOrder[0] == blockOrder.slice(-1)) {
            shuffle(subOrder);
        }
    }
    blockOrder = blockOrder.concat(subOrder);
}

I have also imported the condition file so I can manipulate it:

trials_panel = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1, method: TrialHandler.Method.RANDOM,
    extraInfo: expInfo, originPath: undefined,
    trialList: 'SF_Panel_Conditions.csv',
    seed: undefined, name: 'trials_panel'
  });

panelList = trials_panel.getTrialList();

Next for each trial I think I need to :

  1. define a trialSet that contains trials from the conditions file that correspond to the current panelmember in order e.g.:
    trialSet = panelList[panelList[“PanelMember”]===blockOrder[trialcounter]]
  2. select a trial at random from this trialSet to be presented this trial (without replacement, i.e. trial should not be shown again).

This is where my hacking skills stop and any advice or suggestions would be much appreciated!

Hey! I’ve got two suggestions:

  1. Don’t edit the JS file directly, because that could make it more difficult to update your experiment to newer versions of PsychoPy later on.
  2. For a loop over some custom-generated array, see this demo: Thomas Pronk / demo_dynamic_loops · GitLab

Thank you very much @thomas_pronk. I will have a look at your dynamic loops!

1 Like