This is an advanced function that you only need rarely. But still, it can be very handy!
The information that can be exchanged must be in integer format. Thus, only whole numbers can be used (no letters, no fractional numbers).

Imagine you have a survey in which people answer in a certain way, and you want to use the answers in your (embedded) experiment.

Example situation in which you can use this technique

For example, you may ask people in the survey how tired they are on a scale from 1 to 10. You can use the "tiredness" score in your experiment to change the speed with which stimuli are presented; just because you may assume that tired people are not thinking very fast and might be stressed out if the experiment is not customized for their situation.

This lesson will teach you how to use PsyToolkit to do the following:

  • have an online survey with an embedded experiment

  • get an answer from the survey into the experiment

  • get a variable from the experiment into the survey

How it works

All you need to do is to add one or two options to the experiment to which you want to send information from the survey or the other way around.

How to do it step by step

Step 1. The example experimental design

Imagine we have a survey in which we ask people how tired they are. And then we run an experiment which uses the tiredness score to give them more time to respond. The experiment sends the average response time back to the survey.

Whatever you do, you need to first think about what you want to do. In the design drawing below, yellow is what happens in the survey questions and in green is the embedded experiment.

design var in out

Step 2. Setup a survey

l: tired
t: range
q: How tired are you?
- {min=1,max=10,start=5,left=not tired,right=very tired}

l: mytask
t: experiment
- speed_measure

l: myfeedback
t: info
q: Your tiredness on a scale from 1 to 10 was {$tired}.
Your average response speed was {$speed_result}

Please note the following: - There are 3 types of 'questions' in this survey: range, experiment, and info - You should have an experiment called 'speed_measure' - Note that in the q: part of a question, you can use variables. The {$tired} is simply the answer as given to the first question - The {$speed_result} variable is taken from the experiment. In the experiment, the global variable &speed_result is sent

Step 2. Setup an experiment

You can set up any experiment for this, as long as you make sure you have the following lines in your options part of the experiment:

options
  var in tired
  var out speed_result

Running the code

Here you can see what this survey and experiment does. You are first asked for how tired you are. Then that variable is used in the experiment. All you need to do is to press the b key as quick as possible when asked. You have more time the more tired you say you are (you get 1000 ms + an extra 100 ms for each tireness point, thus you can get up to 2000 ms longest)

The PsyToolkit code

options
  var in tired
  var out speed_result

fonts
  arial 18

task quick
  keys b
  set &my_max_speed expression 1000 + &tired * 100
  show rectangle -200 -200 30 30   255 255 0
  show rectangle -200  200 30 30   255 255 0
  show rectangle  200 -200 30 30   255 255 0
  show rectangle  200  200 30 30   255 255 0
  show text "Press the b key, please"
  readkey 1 &my_max_speed
  clear 1 2 3 4 5
  if STATUS == 1
     show text "Well done! Your response time ="
     show text RT 0 100
     delay 1000
     clear -1
  fi
  if STATUS == 3
     show text "Too slow. Are you tired?"
     delay 1000
     clear -1
  fi
  save STATUS RT

block test
  tasklist
    quick 10
  end
  feedback
    text align left
    set &speed_result mean c2 ; select c1 == 1
    text -200 -200 &tired ; prefix "You tiredness score from survey was: "
    text -200 -50 &my_max_speed ; prefix "Your maximally allowed speed: "
    text -200 100 &speed_result ; prefix "Your speed in correct trials: "
    text -200 200 "Press space bar to continue"
  end
If you specify a variable as "var out", it will later automatically be available in the survey and also in the downloadable spreadsheet. This is particularly useful if you are not interested in any further data analysis of the "raw" data. That sometimes happens. This is a way just to use some information from the experiment and very easily hand it over to the survey.

Any questions?

Hopefully, this helps you to set up your own study. If you still have questions, just let me know via email.

You can also exchange information between surveys and other websites. That is a different topic. But ultimately, you can get a value from an experiment to the survey and then from the survey to another website (if that is what you want, it is not a common scenario). Learn more about that in this separate lesson: Let PsyToolkit exchange information with other website.