Skip to content
Jack Brookes edited this page May 30, 2018 · 13 revisions

Our Session component contains our Block objects, each of which contains Trial objects. These need to be manually created and ordered in the way our experiment requires.

Generation

A common way to generate the blocks and trials for the session would be to call a method using the OnSessionBegin UnityEvent that generates the blocks and trials for us.

Below is an example MonoBehaviour script that will perform the generation:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

// add the UXF namespace
using UXF;

public class SessionGenerator : MonoBehaviour
{     
    public void GenerateExperiment(Session experimentSession)
    {
        // retrieve the n_practice_trials setting from the session settings
        int numPracticeTrials = Convert.ToInt32(session.settings["n_practice_trials"]);
        // create block 1
        Block practiceBlock = session.CreateBlock(numPracticeTrials);
        practiceBlock.settings["practice"] = true;

        // retrieve the n_main_trials setting from the session settings
        int numMainTrials = Convert.ToInt32(session.settings["n_main_trials"]);
        // create block 2
        Block mainBlock = session.CreateBlock(numMainTrials); // block 2

        // here we set a setting for the 2nd trial of the main block as an example.
        mainBlock.GetRelativeTrial(2).settings["size"] = 10;
        mainBlock.GetRelativeTrial(2).settings["color"] = Color.red;

        // we enable a setting if this is the first session, e.g. to show instructions
        session.GetTrial(1).settings["show_instructions"] = (session.number == 1);

        // we can also do different things depending on participant information
        int age = Convert.ToInt32(session.participantDetails["age"]);
        session.settings["sensitive_content"] = age >= 18;

    }
}

Why?

It is very common in human behaviour research to change the structure of the session

๐Ÿง  Core topics

โ“ More help


๐Ÿ‘ฉโ€๐Ÿ’ป Programming reference

Unit tests

Clone this wiki locally