Adding Instructions

Adding Instructions

Located in ExampleScripts - instructions_example.py

Here is how you can add instructions that will show up in either a headset (wherever the user looks) and on the mirrored desktop view. This can be triggered using any event (such as a yield viztask.WaitTime ). This code is also under the "Examples" folder.  The default for skipping past the instruction is either with the left mouse click or controller trigger for single user and SPACEBAR on the server with multi-user

For SightLab_VR (3D Models Single User)  For 360 Videos and Multi- User see below

#add the lines: 

import viz, vizfx, vizconnect, viztask

from utils import sightlab

from settings import *

from utils import instructions


#Code to disable the GUI from showing (set to 1 if you want the GUI)

sightlab.is_GUI = 1


#run sightlab experiment

def sightLabExperiment():

#set to true before starting experiment

sightlab.setInstructionsFlag(True)

yield viztask.waitKeyDown(' ')

viz.sendEvent(TRIAL_START_EVENT)

#Place your instructions where it says 'test' in example

instructions.instructions.message('test')

#Add whatever trigger you want to click past instructions

yield viztask.waitEvent('triggerPress')

#May need to turn headlight back off

if HEADLIGHT_OFF == True:

sightlab.headLight.disable()

instructions.instructions.message('')

sightlab.setInstructionsFlag(False)


yield viztask.waitKeyDown(' ')

viz.sendEvent(TRIAL_END_EVENT)

viztask.schedule(sightlab.experiment)

viztask.schedule(sightLabExperiment)


Non- GUI Version

#Note remove this code if copying this code into the root folder of your project

import os

original_cwd = os.getcwd()

os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))


import viz, vizfx, vizconnect, viztask

import settings

def update_settings(setting_name, value):

setattr(settings, setting_name, value)

update_settings('INSTRUCTIONS_ON_QUAD', True)


from utils import sightlab

from settings import *

from utils import instructions


#Code to disable the GUI from showing (set to 1 if you want the GUI)

sightlab.is_GUI = 0


#Example showing how to set environment. Note that environment should be defined before objects of interest

env = vizfx.addChild("utils/resources/environment/dojo.osgb")

sightlab.objects.append(env)

env.visible(viz.OFF)


#set number of trials

sightlab.sceneConfigDict["trials"] = 3


#run sightlab experiment

def sightLabExperiment():

#Place here if only at the start. Text after .message('')

instructions.instructions.message('Look Around the Room \n\n Press Trigger when Ready')

for i in range(sightlab.sceneConfigDict["trials"]):

#Place here if start of every trial

# instructions.instructions.message('Look Around the Room \n\n Press Trigger when Ready')

yield viztask.waitKeyDown(' ')

viz.sendEvent(TRIAL_START_EVENT)

env.visible(viz.ON)


instructions.instructions.message(' ')


#May need to turn headlight back off

if HEADLIGHT_OFF == True:

sightlab.headLight.disable()


yield viztask.waitKeyDown(' ')

viz.sendEvent(TRIAL_END_EVENT)

#For showing instructions at the end of the last trial

if i >= sightlab.sceneConfigDict["trials"] - 1:

print('All trials completed')

instructions.instructions.message('All Done')

env.visible(viz.OFF)

sightlab.headLight.enable()


viztask.schedule(sightlab.experiment)

viztask.schedule(sightLabExperiment)

If wanting to add instructions mid-experiment (and not just at beginning) will need to manually turn on and off the environment model and the headlight:

yield viztask.waitTime(4)

sightlab.headLight.enable()

sightlab.objects[0].visible(viz.OFF)

instructions.instructions.message('Test')

yield viztask.waitEvent('triggerPress')

sightlab.objects[0].visible(viz.ON)

if HEADLIGHT_OFF == True:

sightlab.headLight.disable()

instructions.instructions.message('')

sightlab.setInstructionsFlag(False)


Note: When using multiple users all clients need to set the instructions flag to the same value (i.e. all to true or all to false)

Another option for adding instructions at specific times and after certain conditions is to use a STIM file


Note: if you want the instructions to show on top of the gray fade quad, change this option in the settings file, or use this code:

import settings

def update_settings(setting_name, value):

setattr(settings, setting_name, value)

update_settings('INSTRUCTIONS_ON_QUAD', True)

from settings import *

from utils import sightlab

For 360 Videos, Multi-User

#Recommended: Add this  code at the top of your script for 360 videos or SightLabVR_Server and  SightLabVR_Client to add instructions per experiment

import viz

import settings

def setInstructionsFlag(boolean):

    settings.INSTRUCTIONS_FLAG = boolean

setInstructionsFlag(True)

settings.INSTRUCTION_TEXT = 'Look at the Scene'

#before importing sightlab modules


Can use the Settings.py file and change  the flag to true and 'Test' to your instructions (note that setting this to True may cause main sightlab.py to display a black screen to click past)

INSTRUCTIONS_FLAG = False

INSTRUCTION_TEXT = 'Test'

You can also use Images for Instructions- See ExampleScripts- ImageInstructions.py and imageInstructions_grabbable.py