Experiment stuck initializing the experiment

Thanks. Now it runs offline.

When I run it online, I get this error. Is this specific to PsychoJS?

Best,
Yusuke (Still up with his 2 year old not wanting to go bed)

I think that might be that JavaScript is trying to use data_array[i][0] before it has been assigned.

You also have 11 append = push errors in RandomizationCode, e.g.
data_array.append(add_this);
needs to be edited to:
data_array.push(add_this);

"Append"s have been edited to "push"es.

I suspect the same. Is there a way to force JavaScript to run a certain portion of a code earlier than the others?

I think I solved this by moving the code component to the top of the first routine. I’ll check when I’m on my laptop later

It looks like .setText is not reading the list correctly. Could you suggest a solution?

I would double-check the contents of the T1…6 arrays with a console.log command. Basically, before text_1.setText(T1[k]), i would just put:

console.log(T1[k]);

Just to make sure there’s something there. If not, I would then go back to the begin-experiment code where you construct these things and use console.log commands to check that they are being constructed correctly, and if not try to isolate the step at which things are going awry.

The output of these console.log commands will appear in your browser’s JS console, which can be found in Chrome by going to View -> Developer.

This is weird. I made sure the code works in PlayCode, and everything is stored correctly into the variables. However, when I call it using text_1.setText(T1[k]);, it fails as if T1 does not have anything in it.

From JS console, it is correctly stored:
TestMarketingJS_codebasedV3.js:348 (20) [“A1:N1”, “A7:N6”, “A13:N11”, “A19:N16”, “A25:N21”, “A31:N26”, “A37:N31”, “A43:N36”, “A49:N41”, “A55:N46”, “Anonymous:N31”, “Anonymous:N36”, “Anonymous:N41”, “Anonymous:N46”, “Anonymous:N51”, “Anonymous:N56”, “Anonymous:N61”, “Anonymous:N66”, “Anonymous:N71”, “Anonymous:N76”]

However, it failed to load for the first trial:
undefined
VM173 core-3.2.js:1061 TypeError: Cannot read property ‘0’ of undefined
at Scheduler.TrialRoutineBegin [as _currentTask] (TestMarketingJS_codebasedV3.js:651)
at Scheduler._runNextTasks (VM178 util-3.2.js:1079)
at Scheduler._runNextTasks (VM178 util-3.2.js:1082)
at Scheduler._runNextTasks (VM178 util-3.2.js:1082)
at update (VM178 util-3.2.js:1046)

That’s odd. I tried to look at line 651 but the code only has 632 lines

I found that the variables that need to be computed were defined twice, inside and outside the trial routine. It was odd that PsychoPy3 autogenerated them twice, but I manually deleted some of them from the JS code. It now works perfectly. Thank you for all of your help.

Best regards,
Yusuke

Jonathan,

Everything works online except that it is not saving values of the two variables that I create in Code. I am trying to save “valence” and “anonymity” using psychoJS.experiment.addData in Code every trial. I feel I need to declare the variables but I do not know if I can do that in the builder. Could you help?

Thanks,
Yusuke

The variables “valence” and “anonymity”, and the indexing variable k, are declared in the begin experiment code, so that should be fine. The code component that adds them to the data in the begin routine code also looks good to me. Is it not working in some way? If you pilot the experiment to the end, does it save those variables in the csv file?

I am not sure why but it now works… Thanks for double checking it for me!

Best,
Yusuke