> For the complete documentation index, see [llms.txt](https://help.imotions.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.imotions.com/lab/study-setup-and-design/other-tools/how-to-z-tree.md).

# How to: z-Tree

Record z-Tree economic games in iMotions Lab on each participant computer, merge the studies and import scenes from the z-Tree time file.

**Introduction to zTree & How to get started**

In the following article, we will cover how to create scenes in iMotions according to stages of a game played with z-Tree. We will provide a brief introduction to z-Tree and describe the appropriate process required on how to record an iMotions study while the z-Tree game is running for correct scene creation.

z-Tree is a widely used software for developing and carrying out economic experiments. The language used to define the experiments is simple and compact, meaning that experiments can be developed quickly, and programming experience is not necessary though very useful. In this article we will illustrate the whole process with the Ultimatum Game (<https://en.wikipedia.org/wiki/Ultimatum_game>: we recommend reading this article in order to get a better feeling for z-Tree and its purpose).

**Z-tree Setup**

This setup requires two machines / computers (one for each participant) and one master machine to start the game, totaling in a three computer setup.

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-9c7be818beaac501e53a9ad966c6f0fa37ea4afe%2Fd7f3a1f9d6_ftsiabsa3ki2x44vho0eyqmceclip0.webp?alt=media)

*Illustration of the connection between the different types of machines (Master / Tree, Leafs)*

You will need to create a shared folder that every machine can access (file server above). There are different ways to do so, but in this example we will use OneDrive. Place the server / master program “zTree.exe” and client program “zLeaf.exe” in the shared folder.

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-65d4765436f1b5b911ab5aedadfe1fcb078aa1cd%2Fa81a45f05a_tl30bhgwzkiu3t8r2oj31amceclip2.webp?alt=media)

Once the shared folder is created:

1. Open zTree.exe from the shared folder on the master computer.
2. Create a shortcut for the zLeaf.exe in the shared folder (Right click zLeaf.exe - Copy - Right Click in the shared Folder - Paste shortcut).
   1. Right click the zleaf.exe (Shortcut) and select “Properties”.
   2. Click on the “Target” field and add in “ /logtime" in order to create the necessary time files (see “Creating time file” for a screenshot of the properties window).
3. Open zLeaf.exe (Shortcut).
   1. The leaves then connect with the tree and await the information sent by the tree (master computer) to play the game
   2. **Note:** If you do not open zLeaf.exe - shortcut, the necessary time file will not be created for scene creation in the analysis.
4. Start the game from the master computer.

Before we give the final command from the master computer to start the game, we also want to record the participants' behavior throughout the game within iMotions.

**iMotions Setup**

1. Create an iMotions study with a screen recording stimulus on one computer
2. Save the study to file
3. Import the study to the other two computers running iMotions that will participate in the game. The screen resolution needs to be the exact same as in the study settings specified at each of the machines. **Note:** Remember to include the sensors you would like to record on the study before saving the study to file
   1. You can follow the steps outlined here if you need further instructions:
4. Create a new participant on both participant computers respectively
   1. **Important:** Make sure to name the respondents and the subjects in this particular way (1, 2, 3,...): Respondent "1" (in iMotions) and Subject "1" (in Ztree) should be using the machine where zLeaf was started / opened first, and so on. You can change the name of a subject in z-Tree when you go to Treatment > Parameter Table and double-click the top cell of every column

5\. Start the recordings for each participant

Now you can start the game from the master machine in z-Tree. The game information is sent to each of the zLeafs (the participants are playing the game).

**Ending the recording:**

Just after the game has ended, switch to the iMotions software on every client’s machine and click “End Slide”.

**Creating the yymmdd\_hhmm\_time.xls Time File**

Once the game is finished in z-Tree and the iMotions recording has ended, several log files are generated by z-Tree. The focus is now on the yymmdd\_hhmm\_time.xls time file generated by z-Tree. This file is not created by default: You have to create a shortcut of zLeaf and add the command line "\logtime" in Properties > Shortcut > Target (see next Picture). The logtime file needed will be generated only if you open the zleaf.exe shortcut instead of the zLeaf.exe.

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-d85606ef36ebd576b5cd5852bb6e6f6cd7b175c4%2Feec76c288b_vjtaomnduyuh8mdy7yv9qmceclip1.webp?alt=media)

*Screenshot of the Properties of Zleaf.exe - Shortcut.*

**In The Time File**

The time file stores the timestamps for when participant inputs are entered and when the screen is updated based on the time kept on z-Leaf. This time is therefore not influenced by network delays and it is not synchronized across different subjects (see next Picture).

**Note**: The names of the participants in the table fit the naming convention we mentioned.

This is what the time file looks like. It contains the start and end times of start of a stage and end of stage which are essential to synchronizing the participants:

![mceclip0.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-29979983308e8ca78391ae76642e618225aced16%2F1734733f29_yhrm7rbnbumtmpvt8onfamceclip0.png?alt=media)

*Extract of the logtime file yymmdd\_hhmm\_time.xls, generated by Ztree.*

We set the respondent names in iMotions equal to the subject names in z-Tree. This is necessary to create a mapping from the subject in z-Tree to the respondent in iMotions (see previous in this article: iMotions Setup - 4.a). In order to enable an import of the z-Tree logtime file information into iMotions and automatically create scenes, the iMotions tool requires a specific layout (see next picture).

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-e9e35e70767b4bb0deee0a33e5676e3141439737%2F03c1f7d6fd_h5fgghfkecjplup7infwmceclip2.png?alt=media)

*Extract of Import.CSV with the desired layout.*

We used an algorithm implemented in R (On request, this can be provided) to change the zTree logtime file into the desired layout (Import.csv). This algorithm will provide the required layout for accurate scene creation in iMotions

**Merge Studies & Scene Creation in iMotions**

At this point, you still have separate studies from every participant machine. Here are the steps to merge the studies together and create scenes for each participant for your analysis:

1. Save the study to file on each participant computer
   1. Right-click on the study name on the participant computer
   2. Select “Save to File” to save the participant recording to a zip file
2. On one computer, load all studies to iMotions
   1. Click on the File menu in the top left corner of iMotions
   2. Select “Load Study from File”
   3. iMotions will suggest to merge the studies
   4. Select to merge and create new participants for the new data
3. Now you have one study containing all respondents and their recordings
4. Now you can create the scenes:
   1. Right-click the study name in the iMotions library (see next Picture)
   2. Select “External Data”
   3. Select “Import scenes” and select the Import.csv file previously created.
   4. The scenes are being generated based on the file you imported

You should now see scenes for all events in the recording:

![](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-be645311d99b5c9a29f8f75e80e74b2933d2db35%2F9b3abd2a80_4unhsxrdn0s1gooaquykugmceclip3.webp?alt=media)

*Screenshot of iMotions Scene Import Creation*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.imotions.com/lab/study-setup-and-design/other-tools/how-to-z-tree.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
