JavaScript - continueRoutine = false -- problem online

@Marc_Buehner, in case you have not fixed it, your current error is because you are missing curly braces on the if statement you just amended. See :

if ([1,2,4,5,6,7,9,10,11,13,14,15,16].includes(nTrials)) {
    // code
}

After this has been fixed, you might have another error for the catchList variable. To fix, move it out of the if ([3,8,12].includes(nTrials)) block of code, and place it under the
responseChecker = 0; statement.

@dvbridges you are a star.
Actually the experiment now crashes with a typeError.
It does not like c1.setPos(catchTrialPos[0][0]);

Great, yes that is because you need to move the catchTrialPos variable to somewhere before it is used, so I would move it to the “Begin Experiment” tab.

The last error regarding the array variable should be fixed using:

for (let thisRater of catchList){
    if ([1,2].includes(thisRater.getRating())){
        var responseChecker = responseChecker +1;
        var index_L = catchList.indexOf(thisRater);
        if (index_L > -1) {
            catchList.splice(index_L, 1);  // use catchList, rather than array
            }
        }
    }

@Marc_Buehner, have a look at the attached, it works, but needs some formatting to get better positioning. I changed the color of the radios so you can see the marker.

v1.5_JS.psyexp (77.5 KB)

Aww thank you @dvbridges!

How do I upload and run it? Sorry must seem like a dat question but I am just not familiar with github.

No worries. You just need to add it to your experiment folder, open in PsychoPy and sync the project, which will create the HTML and JS and send it to Pavlovia.

@dvbridges I am so sorry to be asking all these basic questions, but without documentation it is a complete blind flight for me:
So I have copied the file into my local directory and renamed it (because I had in the meantime also worked more on my own version). I synch the project and can see that your file is uploaded to Pavlovia, but how then do I run it? Even when I open your file in builder and then press the run online button, it actually runs the later version I created. How do I tell pavlova which of the JS files in the directory to run?
Thanks

I would move all unused versions of your experiment to a different folder (or just delete them), close PsychoPy, delete the HTML folder in the experiment folder, open the new version of the task in PsychoPy, and sync to Pavlovia. This should clear your html folder and leave only the new version.

That didn’t seem to have worked — I have deleted all but your file locally and also deleted the local html folder.
When I press the synch button nothing happens, but when I go the project info button, I can synch via that.

I cannot run the experiment online via PsychoPy, so I go to Pavlovia and all the old files are still there and when I click on pilot from there, it runs my most recent version…

Ok, it means that it is not exporting correctly. Can you please open Coder, and then sync again from Builder. There should be some error messages popping up on the Coder output window.

Indeed!
FileNotFoundError: [Errno 2] No such file or directory: ‘/Users/marcbuehner/Documents/research/experiments/PsychoPy/ImmJustice/html/v1.5_DVD_JS.js.txt’

Perhaps I should not have deleted the html directory?

The HTML directory will be recreated each time you export the HTML. I am not sure why you have a .txt file in place of your JavaScript file. This is what your file directory should look like:

ImmJustice
------ html
------|------index.html
------|------v1.5_JS.js
------|------v1.5_JS_noModule.js
------|------Resources
------|------|------Each of your conditions files
------|------|------Resources
------ v1.5_JS.psyexp
------ v1.5_JS.py python files (if ran locally)
------ your conditions files

You may have to copy the conditions files into the resources folder if they are not there.

Ah – I think the problem was that when I downloaded your file MacOs helpfully added an invisible .txt extension. That’s what confused PsychoPy and didn’t allow the sync. I thus saved your file again and now it did synch. I copied the condition files over.
But now I get:
Unfortunately we encountered the following error:

  • when starting the experiment
  • when opening a session for experiment: MJB/immanent-justice-v1-3
  • when opening a new session
  • the pilot token is missing

Try to run the experiment again. If the error persists, contact the experiment designer.

Great. Go to :https://pavlovia.org/MJB/immanent-justice-v1-3 and change the status of your study to “pilot” and refresh your browser.

that does not seem to make a difference. Tried it in 2 browsers

Sorry about that @Marc_Buehner , try changing the status to running instead.

Excellent – thank you @dvbridges that worked.
However, the experiment is still broken: On the catch trials, the stimuli are not showing as they should.
Specifically, the code in lines 1113f that sets the text for elements c1-c5 and ts is only partially evaluated.
It shows the value of thisPerp, but does not seem to do the catchStims.pop() part. I thought I had reformatted this according to your instructions.

I see, this is because of the ordering of the components in the catch routine. Right click the code component in the catch routine and select “move to top”. Now, all your text for the catch text components will be created before it is fed to the text component. Also, you should resize your sliders for the catch trials to make them smaller e.g., (.1, 0.01). You may also want to reposition your text that is presented for the catch trials

You are such a star @dvbridges – thank you.
I had the code on top of the routine initially but then thought I had to move it down – cannot remember why.
I think the (hopefully!) last outstanding issue is the positioning of the items on the catch trial. I read your reply to another post about aligning/positioning text in JS and how that differs from py.

So there are 2 main problems:
a) how can you actually make text that is just 1 line appear left aligned so that it looks neat in a list?
b) I don’t understand why the y position of my text elements cs1-5 and trueStatement does not correspond to the y position of the sliders, when the code should mean they are identical:

catchTrialPos = [[[-.6,.3],[.7,.3]],
[[-.6,.2],[.7,.2]],
[[-.6,.1],[.7,.1]],
[[-.6,.0],[.7,0]],
[[-.6,-.1],[.7,-.1]],
[[-.6,-.2],[.7,-.2]]];

The 1st pair is x & y coordinates for the text, the 2nd pair for the corresponding slider

Yes, its not obvious that is makes a difference until you look at the code and see that the order has changed.

a) Try setting the text wrapWidth to something like .3 (see explanation)
b) It looks like default and only units for Slider are height units. You just need to figure out what units correspond. Norm units on the Y axis are twice that of height units e.g., position y=.5 in norm units is y=.25 in height units.