Problems with addData() after shuffle function

URL of experiment: GitHub - PaigeKemp/Face-Project
Experiment is named “OtherRaceEffect” and all the relevant files to run the experiment are located in the URL above.

Description of the problem: I am trying to add what character (A, B, or C) has been chosen via the shuffle function to the output file. However, the output never shows the what I want to “add.”
Here is the code I am using in the Begin experiment tab:

chars = ["A", "B","C"];
shuffle(chars);
condition = chars[0];

Cond_Loop.addData(‘Condition_Chosen’, condition)

I have also tried to move the Cond_Loop.addData(‘Condition_Chosen’, condition) to the begin routine and end routine tabs but I have had no success.

Does anyone know how to figure this out?

I always use thisExp.addData with thisExp defined in code_JS as per my crib sheet

Hello,
In accord to your advice and the crib sheet I added a code_JS to my experiment with the following written in the begin experiment tab with JS Code:

thisExp = psychoJS.experiment;
win=psychoJS.window;
event=psychoJS.eventManager;
webbrowser=window;

The code in the message stated earlier is in a separate code component under the begin routine tab:

chars = ["A", "B", "C"];
shuffle(chars);
condition = chars[0];

with

thisExp.addData('Condition_Chosen', condition)

in the end routine tab of that code component.

However, I am still not getting any “add.Data()” in my final output excel sheet. Any ideas on why?

Thanks for your time!

An alternative solution for this issue would be to add the file name of the ‘.xlsx’ which is being imported to the final csv ouput. I was unable to locate code on how to append that information.

Have you defined shuffle in code_JS

In order to work out what’s going on you might need to print (auto translate to console log) some values.

e.g.
console.log(“chars”,chars);
console.log(“condition”,condition);

Then look in the developer console to see if the values are working.

Hello,

Thank for the reply, I changed the code to define the shuffle in code_JS. I am very new to PsychoPy and so I have tried to do some research on what you mean by “print (auto translate to console log) some values” however, I am still very unsure on what this actually means and what I have to do to my code to resolve this issue.
Sorry about this issue and I will continue to expand my knowledge of PsychoPy