Why does expInfo['participant_number'] and participant_number work in a trial routine but not when creating an online link. Is this a bug?
Details
I want to use PsychoPy (v2024.2.1) to handle my to counter balancing and to retrieve the participant number and finally to create a daisy chain so the next component can use the information.
I get the participant_number from the shelf
// fetch the current value on the shelf (this variable is displayed in text)
participant_number = await psychoJS.shelf.getIntegerValue({key: ['participant_number'], defaultVlaue: 0})
participant_number = participant_number + 1
// https://www.psychopy.org/online/shelf.html#interacting-with-integer-records
expInfo['participant_number'] = participant_number
// increase the value on the shelf by 1
psychoJS.shelf.addIntegerValue({key: ['participant_number'], delta: 1})
Within the trial routine, I can access this information via expInfo['participant_number'] or by just using participant_number. See:
$f"You are Participant {participant_number}" + expInfo['participant_number']
However, this doesn’t work for the daisy chain. In the settings dialog box under online I set (as shown here Daisy Chaining Between 2 PsychoPy/Pavlovia Experiments - #4 by wakecarter): $"https://run.pavlovia.org/pavlovia/survey-2024.2.0/?surveyId=b6998c40-7941-4eda-ad0e-b2f9712187aa&participant=" + expInfo['participant_number']
The resulting link is: https//....ad0e-b2f9712187aa&participant=undefined
Just using participant_number also doesn’t give me the result that I want.
PS: counterbalance.remaining also returns undefined even it is seem to be able to access the shelf information.
but I still get undefined. It’s also odd that the option for such redirect still exists in the version even if the variables are all inaccessible. I am a bit confused.
As per Jon’s post, you have to start with something in the redirect links in order to change it in code.
There hasn’t been a change. You can add variables in the redirect links in Experiment Settings, but only ones available at the experiment start (i.e. from the expInfo dialogue)
For the counterbalance, perhaps .remaining only works with the old counterbalance version.
but it unfortunately still does not work. I mean it does create a link but to the code routine at the end participant_number (or expInfo['participant_number']) still does not exist.
Sorry yes, the link it generates is https://run.pavlovia.org/pavlovia/survey-2024.2.0/?surveyId=b6998c40-7941-4eda-ad0e-b2f9712187aa&participant=undefined.
It works when I put everything in one code routine like:
// fetch the current value on the shelf (this variable is displayed in text)
participant_number = await psychoJS.shelf.getIntegerValue({key: ['participant_number'], defaultVlaue: 0})
participant_number = participant_number + 1
// https://www.psychopy.org/online/shelf.html#interacting-with-integer-records
expInfo['participant_number'] = participant_number
// increase the value on the shelf by 1
psychoJS.shelf.addIntegerValue({key: ['participant_number'], delta: 1})
//set URL
completedURL = "https://run.pavlovia.org/pavlovia/survey-2024.2.0/?surveyId=b6998c40-7941-4eda-ad0e-b2f9712187aa&participant=" + expInfo['participant_number']
psychoJS.setRedirectUrls(completedURL, "");
but I thought that the variables should be available to other code routines. Is that not true?
If you put participant_number = 0 in the Begin Experiment tab of an auto code component (or indeed anywhere before you reach your JS code) then the variable will get defined to have scope across the whole experiment.
I think I have to learn more about it because I defined participant_number in a code routine and it was accessible in a later text routine but not in another code routine later on. I will follow a couple more tutorials that hopefully clears things up.