LogoLogo
  • Introduction
  • Getting Started
    • Setup
      • Windows WSL Instructions (new)
      • Windows WSL Instructions
      • Linux Instructions
    • Creating your experiment
    • Running your experiment
    • Updating your experiment
  • Conceptual Overview
    • Game Life Cycle
      • Customising when players submit stages
    • Concepts
    • Randomization & Batches
    • API
  • Guides
    • V2 Migration
    • Managing the Data
    • Special Empirica Components
    • The Admin Panel
    • Deploying Your Experiment
      • Ubuntu tutorial
  • Tutorials
    • Beginner Experiment: Prisoner's Dilemma
      • Part 1: Before you start
      • Part 2: Creating the Experiment in Empirica
      • Part 3: Getting Accustomed to the Code
      • Part 4: Coding the Prisoner's Dilemma Game
        • Part 4.1: Removing example code
        • Part 4.2: Intro Text
        • Part 4.3: Set up the game stages
        • Part 4.4: Build the "Choice" React Component
        • Part 4.5: Build the "Result" React Component
        • Part 4.6: Compute the Score
      • Part 5: Customizing the experiment
        • Part 5.1: Changing the number of rounds
        • Part 5.2: Turning the chat on and off
      • Part 6: Deployment
  • FAQ
    • I need help!
    • The Processes and Elements of an Empirica Experiment
    • Managing Players and Games
  • Resources
    • Helpful Linux Commands
    • Code Editors
    • Javascript and React
  • Links
    • Empirica website
    • Twitter
    • GitHub
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Tutorials
  2. Beginner Experiment: Prisoner's Dilemma

Part 3: Getting Accustomed to the Code

PreviousPart 2: Creating the Experiment in EmpiricaNextPart 4: Coding the Prisoner's Dilemma Game

Last updated 10 months ago

Was this helpful?

To get a glimpse of the actual code that runs Empirica, open Visual Studio Code to the prisoners-dilemma folder.

You can either do this manually, by going to File > Open Folder and selecting the prisoners-dilemma folder, or by typing in your terminal code . within the prisoners-dilemma directory.

The template experiment includes three subdirectories:

  1. .empirica stores data and config files that we need to run the experiment.

  2. client is where the code that runs on your experiment participant's browser lives.

  3. server is where all the code that runs on the server lives.

The client and server directories are each structured as a node package, and contain some boilerplate code that we can ignore:

  • node_modules/ is a folder containing dependencies, and is managed for us (we never need to touch it)

  • dist/ is a folder for the compiled version of our code, which gets built automatically

  • package.json and package-lock.json contain references to other packages that our experiment depends on

  • client/index.html, client/vite.config.js, client/uno.config.ts, client/jsconfig.json server/jsconfig.js are all configuration files we can leave as they are

In this tutorial, we will make changes in the following places:

  • client/src/ is a folder containing the views the participant sees, built up as React components.

  • server/src/callbacks.js is a file for server-side code that is called when specific actions happen in the game.

  • .empirica/local/tajriba.json is where our experiment data is stored. It is often helpful to delete this file when you restart the server, to start with a clean slate.

Have a quick browse through the files in client/src/examples to see how the jelly bean and minesweeper examples are implemented.

Collapsed File Tree