Part 4.1: Removing example code
When you create an experiment with the empirica create
command, Empirica populates a template experiment with the jelly bean and minesweeper code that you saw in the previous step. We won't use this example code in our experiment, so let's clean it out. There are a few steps:
delete the entire
client/src/examples
folderIn
client/src/Stage.jsx
:remove the imports for
JellyBeans
andMineSweeper
(2 lines)replace the
switch
statement and its three cases (8 lines, including brackets) with the code `
The file should look like this when you are done:
In the
server/src/callbacks.js
file:empty the contents of the
onGameStart
andonStageEnded
functions, keeping the function definitionsdelete everything after the empty function definition for
Empirica.onGameEnded({})
.
When you are done, the file should look like this:
Note: In JavaScript, a callback function is a function that is passed as an argument to another function and is invoked or called at a specific point within that function's execution. The callback function is typically used to ensure that certain code is executed only after the completion of a specific task or operation. In our case, these callbacks are invoked when parts of the experiment start and end.
Restart empirica
Now we can restart Empirica to have it reflect our changes. The command below will remove our existing datafile and start the server.
At this point of the tutorial, you should be able to start a new game on the admin site (http://localhost:3000/admin/).
At this stage, if we login as a participant (by visiting http://localhost:3000), the game will be stuck in loading, as we haven't yet added any content - that's what we'll do next!
Last updated