Special Empirica Elements (and how to modify them)
Centered
The Centered component is a custom element from Empirica that you can use to surround other elements of your components. This will make them centered on the page.
Import the element with:
And use it like this:
Timer
There is a Timer.jsx
component that represents the stage timer and shows players how much time is left at that stage.
For the Timer to work, the stage
has to be passed down to it as a prop. For example, in the PlayerProfile.jsx
of your first Empirica experiment:
Inside the Timer.jsx
component, what makes the timer is that it extracts the remainingSeconds
from the stage
, and that it imports the StageTimeWrapper
to export the Timer with export default (Timer = StageTimeWrapper(timer));
.
Here is the code for a basic Timer component:
About Section
The About section is a small window that will upon when players click the top right corner button About
. For example:
In client/main.js
you can set your custom component for the About section.
Import the component to the client/main.js
with:
And then set it with:
However, setting an About section is completely optional, you can get rid of it by not writing the Empirica.about
line in client/main.js
or deleting it if it is already written.
Header
The Header is the blue rectangle at the top of the page in an Empirica app.
See more about the structure of the Header component here.
Import the component to the client/main.js
with:
And then set it with:
Or you can get rid of the Header with:
Special Dev Wrap Header
If you don't want the blue header to show, especially not when you deploy your experiment, but you still want to access the Reset Player
and New Player
buttons during development, you can surround each of your important components (e.g., Round.jsx, Intro steps, etc.) with this special component:
For example, to have it show in each round, import it into the round component and use it this way:
Breadcrumb
The Breadcrumb is the track at the top of a Round that shows the player which Stage of the Round they are currently at.
See more about the structure of the Breadcrumb component here.
In client/main.js
you can set your custom component for the Breadcrumb.
Import the component to the client/main.js
with:
And then set it with:
Or you can get rid of the Breadcrumb with:
NewPlayer (where players set their id)
Players have to set their id at a NewPlayer page just after the consent page. This could be a name, an MTurk/Prolific id, a student id, an email, etc.
You might want to change its design, format, or instructions. For example, if you want participants to provide a student id but no other personal information, you would want to make your own clear instructions.
The default NewPlayer.jsx page looks like this:
The important parts of your component is to have methods to handle when the player is changing the id they write (handleUpdate
) and when the player clicks the submit button (handleSubmit
) so that in the end it is using the handleNewPlayer()
method that will set the player's id as the string submitted and moves the player to the first Intro Step.
You can either modify the NewPlayer.jsx
file, or create a new one and set it in the client/main.js
.
If you want to create a new file:
Import the component to the client/main.js
with:
And then set it with:
Lobby
In the Admin Panel, in the Configuration tab, in Lobby Configurations, you can set important aspects of the Lobby such as:
The
Timeout Type
(whole lobby or individual)The
Timeout Duration in Seconds
The
Timeout Strategy
(fail, ignore)The
Extend Count
But you might want to customise your Lobby even further (e.g., change what it looks like or what is written). To do so, you can create a custom Lobby component. It will receive two props, the player
and the gameLobby
. The gameLobby
can be used to extract the following properties in the customising of your Lobby:
gameLobby.treatment.playerCount
will give you how many players the Game expectsgameLobby.queuedCount
will give you the total number of players queued for this game, including ready players and players currently going through the intro steps.gameLobby.readyCount
will give you the number of players ready to play. They have completed the intro steps, and they are on the lobby page.
For a better idea of what you can do and customise, see the default version of the Lobby here.
Once you have created your custom Lobby component, you can import the component to the client/main.js
with:
And then set it with:
Can I add a chat to the Lobby?
To add a chat to the Lobby you need to install the Empirica Chat with:
Then you can use the default Lobby with chat. Do so by importing the LobbyChat
component of this package in your experiment's client/main.js
file, like this:
And setting it to the lobby like this:
Or you can manually add a chat to your customised Lobby.
Empirica Chat
To add a chat in Empirica, you can use our simple solution by using the Empirica Chat. For detailed information about Empirica Chat, see here.
Installing
First, install Empirica Chat with:
Import and Usage
In the components you want to use the chat, import this:
Then you can create the chat component with:
chat
expects 2 required props:
player
: the current playerscope
: object that the chat will be attached to, can be game, round, or stage objects.
Scoping
The scope is important because it determines where the chat data (the messages) will be stored. You can access them again afterwards based on the scope. For example, if the scope is set to the Round:
Multiple chat instances within the same scope
You can pass an optional customKey
string prop to differentiate different chats within the same scope. This changes which get/set key on the given scope the chat will be recorded.
Display names
Chat
also displays a name for each participant, which you need to set in the experiment independently of the playerId
: player.set('name', "myPseudonym")
Adding timestamp to chat message
You can pass an optional timeStamp
date prop to add the timestamp attribute on each message sent.
Run this command to add mizzao timesync:
You can pass an optional timeStamp date prop to add the timestamp attribute on each message sent:
Other functionalities
There are many other functionalities with Empirica chat that you can see here.
Last updated