Okay got it. I’m going to be writing code in JavaScript here because it’s what I’ve been using in PsychoPy and I don’t want to look up the Python equivalents. If you’re running this on Pavlovia, you can just make a JS only code and copy/paste my code, or you can find the Python equivalents if you’re running it locally.
So you’re going to make a loop around the three routines (let’s call it shoppingLoop
) and set it to loop 999 times. Then you’re going to have your three routines with everything you want in it (let’s call them scenario
, items
, checkout
). At the top of each routine, make a code component:
scenario
routine:
Begin Experiment:
loopPage = 0; //this will set it to start on page 1
Begin Routine:
//only do this routine if we're on this page
if (loopPage !== 0) { //if we're not on the first page
continueRoutine = false; //don't run this routine
}
Each Frame:
if (mouse.isPressedIn(nextButton)) { //if they click on the next button component with the mouse component
loopPage++; //increase the page number to 1
continueRoutine = false; //end the routine
} else if (mouse.isPressedIn(exitButton)) { //if they click on the exit button component
shoppingLoop.finished = true; //end the loop to go to your "why?" page outside of the loop
} //don't have a back button on page 1 because where would they go back to?
items
routine:
Begin Routine:
//only do this routine if we're on this page
if (loopPage !== 1) { //if we're not on the second page
continueRoutine = false; //don't run this routine
}
Each Frame:
if (mouse.isPressedIn(nextButton)) { //if they click on the next button component with the mouse component (the components will have different names now because they're in a new routine, so make sure to change them here too)
loopPage++; //increase the page number to 2
continueRoutine = false; //end the routine
} else if (mouse.isPressedIn(lastButton)) { //if they click on the go back button component
loopPage = (loopPage - 1); //decrease the page number back to 0
continueRoutine = false; //end the routine
} else if (mouse.isPressedIn(exitButton)) { //if they click on the exit button component
shoppingLoop.finished = true; //end the loop to go to your "why?" page outside of the loop
}
checkout
routine:
Begin Routine:
//only do this routine if we're on this page
if (loopPage !== 2) { //if we're not on the third page
continueRoutine = false; //don't run this routine
}
Each Frame:
if (mouse.isPressedIn(nextButton)) { //if they click on the next button component with the mouse component (the components will have different names now because they're in a new routine, so make sure to change them here too)
loopPage++; //increase the page number to 3
continueRoutine = false; //end the routine
} else if (mouse.isPressedIn(lastButton)) { //if they click on the go back button component
loopPage = (loopPage - 1); //decrease the page number back to 0
continueRoutine = false; //end the routine
} else if (mouse.isPressedIn(exitButton)) { //if they click on the exit button component
shoppingLoop.finished = true; //end the loop to go to your "why?" page outside of the loop
}
End Routine:
if (loopPage === 3) { //if you're out of pages, end the loop
shoppingLoop.finished = true;
}
So what this does is loop through all of the routines in your loop every time they click any button, but it will skip the two routines that you aren’t currently on using the loopPage
number. After they click ‘next’ on the final page, it will end the loop and go to your next routine outside of the loop, which should be your “why?” page. But you only want them to go to that page if they click exit, not if they finish the loop. So you’ll also want a code component in that routine and in the “Begin Routine” tab, write:
if (loopPage === 3) { //if they clicked 'next' on the final page
continueRoutine = false; //skip the routine
}
I know that was a lot, but I hope that helps!