Conditional Branching: PsychoJS only show following routine, if certain key is pressed

URL of experiment: Sandra Tyralla / 2021_MG_ExPra_LDT · GitLab

Description of the problem:
What I am trying to do is the following:
I have a routine “mothertongue”, where the participant should press ‘d’ for German, ‘a’ for other or ‘b’ for billingual. The following routine “lang_demo”, which is asking the participant to type in all their mothertongues, should only appear, if they pressed ‘b’ on the previous Routine “mothertongue”.

I tried the following:
I put
if (key_resp_3.keys.length) {
if ((key_resp_3.keys.lower() !== “b”)) {
continueRoutine = false;
}
}

In the prepare to start routine section of “lang_demo”. key_resp_3 is the key response name of the mothertongue Routine.

I would appreciate any advice!

Hi, if I am understanding your task correctly, you want to present lang_demo if participants responded with ‘b’ in mothertongue right? I would suggest that in your lang_demo routine, you use a code component (with Code Type set to Auto → JS) where in the Begin Routine tab, you use the following code:

if key_resp_3.keys=='b':
    continueRoutine = False

and the JS equivalent would automatically be translated.

I tried this already with the translated JS code:

if (key_resp_3 != “b”) {
continueRoutine = false;
}

However the following error occurs on Pavlovia:
key_resp_3 is not defined.
It is defined though, as I use it in the Routine before and it’s running fine until I add this to the Begin Routine part of the JS code. I don’t know how to solve this.
I changed quite a few things so I cant go back to the builder.

Further, I have tried to use this in a very short experiment in the builder which worked out fine (just using !=“b”), but as soon as I uploaded in Pavlovia, the lang_demo routine is not skipped when the answer is anything other than “b”

Sorry I might be misunderstanding here but you want lang_demo to be skipped when ‘d’ and ‘a’ is pressed but not ‘b’ right?

Yes exactly, so the Routine lang_demo should not continue (continueRoutine = false) when key_resp_3 != “b”

I think I know what is going on here. In your code, it’s key_resp_3 but it should be key_resp_3.keys

And further, what I just figured:
When uploaded to Pavlovia, the code of the BeginRoutine tab is placed in the //Prepare to start routine section, however it mus also be in the each frame section, otherwise it does not work!

Thank you for you help.