Part 5.2: Turning the chat on and off
In the standard prisoner's dilemma experiment, participants are not able to communicate with one another. We've left the chat enabled from the template experiment up until this point, but now we should set up a flag to enable or disable it, so we can measure the effect of the chat on the outcomes of the game.
Create a factor and treatments
Let's return to the file .empirica/treatments.yaml
. As we did when we changed the number of rounds, we'll create a factor for the chat:
We update our existing conditions, and create new ones with the chat in different states. This time, we'll set the default behavior of the chat to be disabled:
As we add additional manipulations to the game, the number of different treatments begins to grow rapidly. Managing this type of complexity is exactly what Empirica was built to accomplish. Imagine creating a separate setup for each of these different conditions, rather than being able to simply parameterize the factors!
Enable or disable chat in the player display
In order to make use of the chat feature, we'll make changes to client/src/Game.jsx
. Notice in this file that the <Chat...>
component is embedded in syntax that looks like this:
All we need to do at this point is replace the left-hand side condition with one that looks for chatEnabled
. We have two changes to make - first to replace playerCount
in the treatment object destructuring line with chatEnabled
:
Then we need to use chatEnabled
in the left-hand side of the short-circuit operation. As chatEnabled
already returns a true
or false
value, we can just use it directly as the left-hand side expression:
Your full code for Game.jsx
should now look like this:
Now when you restart empirica and play through a game, you'll be able to turn the chat on or off by selecting the appropriate treatment condition.
Last updated
Was this helpful?