Description of the problem:
(1) my objects have disappeared, there should be objects popping up one at a time for a few seconds at a time against the background grid. I have a similar task where the objects pop up fine.
(2) when I get to the phase which has code components in it I get and that’s as far as it will go:
TypeError: Cannot read property ‘xloc’ of undefined
Well, know that online experiments are ran using JS in the code components, it does not read regular Psychopy code (as the desktop version), so if you are using an older version of Psychopy that might be the problem, you would need to translate it to JS. However, if you use the newest version 2020.1 it has an auto-translation feature. Try that and see how it works. Other option is to manually translate your code snippets and open your code component window, selec code: BOTH and write the translation in the right column.
Thanks for getting back to me. I’m using the latest version and used py > autojs.
I have no idea how to manually translate to js - I spent a lot of time changing my python code so that it would work with auto js (I had a previous working version in psychopy which didn’t translate well).
@TomH, looks like the issue is that you have declared the position variables from your conditions file, in a code component. This, I think, has somehow interfered with how the trialhandler is declaring your position variables. To fix, remove your xloc and yloc declarations from your code component.
I tried removing xloc and yloc declarations and then it started complaining about the ‘object’ declarations - are you saying that I can’t refer to anything at all in my conditions file?
So have I to basically recreate these variables (xloc, yloc, object) in my code component, give them a new name and use them for the code component?
The only change you will need to make is to the first routine, where you define xloc and yloc at the beginning of the experiment, in the code component. By removing these, you do not interfere with those variables defined in your conditions file. There is also another change that you might want to make. In another code component, you overwrite xloc and yloc with new values, which are fed to your polygon stim. Change the name of the variables from xloc and yloc, to something different from that in your conditions file, and use these values to set your polygon location (if that is what you planned).
No, in your first routine of the experiment, you had a code component called code_3, which appears to have been removed now. That was causing the issue, because it had the variables xloc and yloc variables defined at the beginning of the experiment. Removing these fixed the experiment for me. I can send you the version I used, if you would like.
Take a look at this URL, to see the changes working:
If you can make a minimum working example to recreate the error, with only single trials for each loop, allowing me to skip all the way to the error quickly, then post the pilot URL, I can try and debug it from here. I do not have easy access to my working version of your task at the mo.
Thanks, its ok I switched machines. The issue was the use of trials.thisTrial['xloc'] in your code component, and other similar expressions. This is not necessary, as you have access to each variable from the current trial just by using the variable name, so trials.thisTrial['xloc'] becomes xloc. To fix, remove any uses of xloc = trials.thisTrial['xloc'] and similar expressions, and just replace with the variable name you are trying to get e.g., xloc.
Once this issue is fixed, you will have another issue, because Pythons range function does not exist in JS, you can write your own though. Add the following code (see source) to a JS “Begin Experiment” tab of a code component - (note, keep auto-translate off for this bit - use code type of “Both”):
function range(start, stop, step) {
if (typeof stop == 'undefined') {
// one param defined
stop = start;
start = 0;
}
if (typeof step == 'undefined') {
step = 1;
}
if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
return [];
}
var result = [];
for (var i = start; step > 0 ? i < stop : i > stop; i += step) {
result.push(i);
}
return result;
};
Because the range function is from stack overflow, you will want to thoroughly check your results, to make sure things like the range function are giving you accurate results. Here is a working example of your task with only 1 trial. The Builder file is attached below.