Arbitrary stage loops in zTree

Written on

If you have to use zTree, you know there are a lot of moments when you just have to copy-paste the same stage several times. And that is not good, because, if you have to make a single change, you have to copy that change to every single stage.

There is a way, however, to circumvent that for most experiments.

Notice in Figure 1 how, for Stage 1, there are many Standard screens.

The cool thing about this? Only one of these is shown at any given time. People press ok on their screens, while the server simply waits for all of them to do just that. When everyone has pressed ok, the server can finally move on to the next screen, without changing the stage.

How is this done? The simplest way would be this:

For each subject, maintain a “HasAnswered” variable. This will tell us if the subject is done with the current screen (a value of 1) or not (a value of 1). We also maintain a “CurrentScreen” variable in the globals table. This can be a number from 0 to anything and it represents the current screen required.

Thus, when pressing an OK button, if the subject has completed all the tasks required on the screen, the HasAnswered variable becomes 1. When the average of all HasAnswered variables is 1 (aka everyone has done the screen), we can change the current screen by altering the CurrentScreen variable to the next value in the chain and reset all HasAnswered variables to 0.

Each screen should have a condition attached to it. “HasAnswered == 0 & CurrentScreen == (YourValue)”. This way, these screens only show up when explicitly told to show up.

For better presentation, you can also have a screen called “Wait”, whose condition is “HasAnswered == 1”. This screen will only show when a user finished earlier than everyone else and still has to wait for people to move on.

Finally, should you eventually want to change the stage, just have a screen with a button that changes stages.

Good luck!