Path too long for Windows error after modifying JS code component

Hello All,

I am constantly receiving the error below. I have a very similar another experiment but only one of them gives this error. I do not know why.

The error occurs when I try to define a correct answer in my code.

Here is a sample from my JS script in my code component. There are repetitions of this code for different conditions.

                        if ((wordChoice[0] === 6)) {
                            thisWord = word6;
                            thisWord_color = "Blue";
                            languageChoice.remove(6);
                            corr_AnsW = wmi_ret6W_2;
                            psychoJS.experiment.addData("corr_AnsW", "wmi_ret6W_2");
                        }
                    }
                }
            }
        }
    }
    util.shuffle(languageChoice);
    psychoJS.experiment.addData("languageN", languageChoice[0]);
    if ((languageChoice[0] === 1)) {
        thisLanguage = language1;
        thisLanguage_color = "Red";
        psychoJS.experiment.addData("Language", 1);

When I try to define correct answer for the language choice (as in the wordchoice), it gives the error.

    util.shuffle(languageChoice);
    psychoJS.experiment.addData("languageN", languageChoice[0]);
    if ((languageChoice[0] === 1)) {
        thisLanguage = language1;
        thisLanguage_color = "Red";
        psychoJS.experiment.addData("Language", 1);
        corr_AnsLan = wmi_ret1W_2;
        psychoJS.experiment.addData("corr_AnsLan", "wmi_ret1W_2");

P.S. I have no information about JS. I hope there is an easy-to-understand solution.
Bests

How many nested elif statements do you have?

I have 5 conditions and within each condition i define 3 different variables to randomly select a number.

What I could not understand:

  1. I am not adding an extra if statement
  2. This does not create problem in other file even though everything is the same except the variable names (no “_2”s in the other)

Thank you

If you manually modified the JS code then I suspect that you have unbalanced brackets.

Copy and paste your JS code into Word and then search for { followed by } to compare the numbers of each.

Yes, I am manually modifying only the code component.

No results found.

Since I can see instances in your post above, I can only assume that you copied and pasted the Python code rather than the JS.

This was working in JS part

corr_AnsW = wmi_ret6W_2;
psychoJS.experiment.addData("corr_AnsW", "wmi_ret6W_2");

I just copied this and changed W to Lan.

Update: When I delete the line I indicated below, the error disappears.

    util.shuffle(languageChoice);
    psychoJS.experiment.addData("languageN", languageChoice[0]);
    if ((languageChoice[0] === 1)) {
        thisLanguage = language1;
        thisLanguage_color = "Red";
        #psychoJS.experiment.addData("Language", 1); # DELETED THIS IN ALL CONDS
        corr_AnsLan = wmi_ret1W_2;
        psychoJS.experiment.addData("corr_AnsLan", "wmi_ret1W_2");

Can this be only about exceeding max amount of Line in a code component?

 if ((languageChoice[0] === 1)) {
        thisLanguage = language1;
        thisLanguage_color = "Red";
        #psychoJS.experiment.addData("Language", 1); # DELETED THIS IN ALL CONDS
        corr_AnsLan = wmi_ret1W_2;
        psychoJS.experiment.addData("corr_AnsLan", "wmi_ret1W_2");

The above code has one { and zero }

I am sorry, not sure if understood it correctly

The { symbol is a bracket.

Every time you use it you are defining a section of code which starts at the { and ends at the next } symbol. If you don’t have a matching } symbol then the computer may assume that all of the rest of your code is part of that section.

In Python indents are used instead of { } brackets.

Try typing the following into an Auto translate code component.

if group == 1:
     continueRoutine = False

The JS translation is:

if ((group === 1)) {
    continueRoutine = false;
}

JavaScript has put ( ) brackets around the statement to be tested and { } brackets around the code to be executed if the statement is true.

1 Like

Thank you so much!!