ChenG
ChenG

Reputation: 19

Creating conditional timelines

I have a timeline with a language selection trial at the beginning. After that trial, I have 3 almost identical timeline versions, with some language modifications in their texts (prompts). I"'m trying to code my script so after the language selection there will be a switching function that will push the correct timeline according to the user's selection. Unfortunately, after this language selection trial, the screen stays blank and the experiment gets stuck. I would appreciate any help. Thanks!

this is my code for the timeline selection:

var switchTimeline = {
            type: jsPsychCallFunction,
            func: function() {
                var languageCode = jsPsych.data.get().last(1).values()[0].language; // Retrieve the language code from the last trial's data
                if (languageCode === 1) {
                    timeline.push(...timelineMALE);
                } else if (languageCode === 2) {
                    timeline.push(...timelineFEMALE);
                } else if (languageCode === 3 || languageCode === null) { 
                    timeline.push(...timelineOTHER);
                } else {
                    console.error("Invalid language code:", languageCode);
                }
            }
        };
        timeline.push(switchTimeline);

I have also tried a different switch function:

var switchTimeline = {
        type: jsPsychCallFunction,
        func: function() {
            var languageCode = jsPsych.data.get().last(1).values()[0].language; // Retrieve the language code
                     switch (languageCode) {
                      case '1':
                          timeline.push(...timelineMALE);
                          break;
                      case '2':
                          timeline.push(...timelineFEMALE); 
                          break;
                      case '3':
                          timeline.push(...timelineOTHER); 
                          break;
                      default:
                          console.error("Invalid language code:", languageCode);
                  }
              }
          };
          timeline.push(switchTimeline);

As you can see, after the user selects a language, it is coded as 1, 2, or 3. In the switchTimeline element, I try to continue the experiment with the corresponding timeline (timelineMALE for 1, timelineFEMALE for 2, and timelineOTHER for 3 or not answering).

Upvotes: 0

Views: 24

Answers (0)

Related Questions