Description of the problem:
I am trying to add a code component to my task in the builder, but I am not experienced with Java and I am finding issue in implementing what I am aiming for.
I want to make the feedback for every trial (fixation cross changing color to red for errors and to green for correct responses) conditional on a column of my condition file. I’m adding a code component in the routine in which I am collecting my responses (two button presses, key_resp and key_resp2)
The way I’m trying to do is to add in the BEGIN EXPERIMENT tab of my code component the following:
var Conditions psychoJS.experiment._trialsData
If I understood correctly, this should import the condition file in a Java-friendly way.
Hi @Silvia, with JavaScript it is normally right to declare your variables e…g, using var, but PsychoPy will do this for you, and create global variables that can be accessed throughout your task. If you use var in the code component, the variable will only be accessible in one part of the experiment, that is, it will be local to the beginning/middle of the experiment, routines etc. So, just remove the var and you are ok.
With var Condition psychoJS... you need to use the assignment operator = to set the value of Conditons e.g. Conditions = psychoJS.... However, this is not doing what you think it is doing. _trialsData is a private variable that contains your response (and other) data from the trials, and there are better options for you here than to use this variable.
If you set the correct answers for each trial in your conditions file, that you use in the loop in Builder, you can refer to those values during the experiment. E.g., add columns “corr_l” and “corr_r” to your conditions file, and fill them with the correct values. Then all you need in your code component is
Therefore, it is as if my first if statement is never True. I wonder if it has something to do with how the response keys are stored and named in Java. I have no idea how to access these info…
Sure that was just a bug that needed fixing, to get to the actual issue the task just needed to run correctly. Is there any chance you could create a minimal working example that gets straight to the issue? Currently there are 1000+ resources that need reloading and takes alot of time to load.
By the way, in JavaScript, you have to use lower case false (as in the example above).