Skip to content
Jack Brookes edited this page May 12, 2021 · 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. With this script, you can then add GenerateExperiment as a call within the On Session Begin event.

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 session)
    {
        // retrieve the n_practice_trials setting from the session settings
        int numPracticeTrials = session.settings.GetInt("n_practice_trials");
        // create block 1
        Block practiceBlock = session.CreateBlock(numPracticeTrials);
        practiceBlock.settings.SetValue("practice", true);

        // retrieve the n_main_trials setting from the session settings
        int numMainTrials = session.settings.GetInt("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.SetValue("size", 10);
        mainBlock.GetRelativeTrial(2).settings.SetValue("color", Color.red);

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

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

Why do it like this?

You may wonder why there isn't an easy visual tool included in UXF to create trials. It is very common in human behaviour research to change the structure of the session in various different ways. For example, you may wish to randomise the order of your trials (using the built-in List<T>.Shuffle() extension). You may also wish to add trials and blocks depending on lots of different conditions. UXF can't be expected to predict all these possibilities - so it currently requires manual, programmatic creation of blocks and trials. It being programmatic, of course means you are free to implement your own method of generating trials. They could be generated from a CSV file, or from some visual tool if someone wants to build one.

๐Ÿง  Core topics

โ“ More help


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

Unit tests

Clone this wiki locally