Problem updating a component parameter that has been imported from trial spreadsheet

URL of experiment: https://run.pavlovia.org/Kielan/foreperiodrtvis/html/

Description of the problem:

My trial loop is randomising (without replacement) from a spreadsheet, but I want to make a small tweak to the order of conditions - basically, replace the final trial with something different. I am randomising stimulus position and foreperiod (i.e. onset time) and it is the foreperiod that I want to overrule.

To do this, I create a counter variable to track where I am up to. Locally with Python, I have inserted a code component at the start of the trial loop which logical tests whether I have reached the critical trial, and if so, updates my foreperiod variable. This seems to work fine (except for not updating it in the results file, but I’m sure that’s easily tweakable).

However, for the JS online variant this hangs the experiment at the start of the first trial. No error message, just gets stuck (testing on Windows 10 / Chrome). Not sure how this arises from my JS incompetence, as it’s just an if statement, but perhaps there is a problem with variable scope or something like that. Suggestions for why this might be happening welcome, or a simple workaround. Here’s the relevant bit as builder has incorporated in the .js script:

function trialRoutineBegin(trials) {
  return function () {
    //------Prepare to start Routine 'trial'-------
    t = 0;
    trialClock.reset(); // clock
    frameN = -1;
    // update component parameters for each repeat
    if ((TrialTo === SurpriseTrial)) {
        ForePeriod = 0.5;
    }

@Kielan, the issue here is that you are overwriting the conditions file variable with your if statement. Change the code to the following, and also change the reference to this variable in your shape and keyboard component:

Python

if TrialTo == SurpriseTrial:
    NewForePeriod = 0.5
else:
    NewForePeriod = ForePeriod

JavaScript

if ((TrialTo === SurpriseTrial)) {
    NewForePeriod = 0.5;
} else {
    NewForePeriod = ForePeriod;
}

Thanks David, that’s fixed it.