How to use

This is the main source code for the experiment. If you want to use it, you should copy the actual zip file to your own PsyToolkit account, because often there are other files included for stimuli.

The source code for pvtb_touch

options
  fullscreen
  resolution fhd
  set &showDetailedFeedback 1 # 0 is official PVT ; 1 gives some useful participant feedback
  ## the static feedback RT is officially same as running color, but green is clearer
  set &staticRedChannel   255 ## if you set this to 0 it is not official, but it is nicer
  set &staticGreenChannel 255
  set &TOTAL_EXP 180000 ## PVT = 600000 = 600s = 10 mintues, PVT-B = 180000 = 180s = 3 minutes
  set &MIN_RT 100 ## RT must be 100 or more, otherwise it is counted as too early.
  set &lapseTime 500 ## what counts as lapse. 500 is standard, but can be set to 355 to match sensitivity of regular

bitmaps
  instructionsPVTBtouch

fonts
  regular arial 20
  medium  arial 40

# in the PVT-B, a trial lasts between 1 and 4 seconds. One of those
# seconds is used for the 1 second feedback to the participant about
# the trial

task pvtb
  font medium
  show rectangle 0 0 200 100 red
  show rectangle 0 0 190  90 black
  set &nTrials increase ## just a simple count of trials (i.e., each time a new stimulus counter starts)
  set $randomDelay random 0 3000 ## the response-stimulus interval is between 0 and 3000 ms
  set $firstround 1
  if &START_TIME_SET = 0
    set &START_TIME_SET 1 ## we only need to start the experimentBeginTime once
    timestamp experimentBeginTime
  fi
  timestamp beginTime
  timestamp now
  # ---------------------------------------------------------------------------------
  # $rtSinceStart = the time since the start of experiment, just for save line
  # rtSinceStimulusOnset = the time so far since the yellow numbers started
  # totalTime = the time so far in the whole experiment (needs to be below TOTAL_EXP)
  # now = is the current time
  # tmpRemaining = in case we reach end of response time
  # ---------------------------------------------------------------------------------
  # this while loop runs every timeframe, like for example 50 ms
  while $keypressed = 0 and $rtSinceStimulusOnset < 30000 and &totalTime < &TOTAL_EXP
    ## each time we go through this while loop we wait 50 ms
    ## it must be so short to create the running timer which needs to be updated
    ## but if we have almost reached max RT it might be less
    ## to deal with that we check it that is the case
    set $maxReadkeyTime 50
    set $tmpRemaining expression 30000 - $rtSinceStimulusOnset
    if $tmpRemaining < $maxReadkeyTime
      set $maxReadkeyTime $tmpRemaining
    fi
    ## now wait up to maxReadkeyTime, which is simethink like 50 or 100 ms
    readmouse l 1 $maxReadkeyTime
    if STATUS != TIMEOUT
      set $keypressed 1
      set $rtSinceStart expression $latestTime + RT ## the time since the start of trial
      if $stimulusPresent = 1
        set $actualRT expression $rtSinceStimulusOnset + RT ## the time since onset of yellow numbers
	if $actualRT >= &MIN_RT and $actualRT <= &lapseTime ## the RT needs to be greater than 100. This is a bit of a grey area I think
          set $outcome 1 ## correct
	fi
	if $actualRT > &lapseTime
	  set $outcome 3 ## lapse
	fi
      else
        set $outcome 2 ## pressed before stimulus
      fi
    fi
    timestamp now
    set $latestTime timestamp-diff beginTime now
    if $latestTime >= $randomDelay
      if $firstround = 1
        timestamp rtBeginTime
        timestamp now
      else
        clear -1
      fi
      set $rtSinceStimulusOnset timestamp-diff rtBeginTime now
      show text $rtSinceStimulusOnset 0 0 yellow
      set $stimulusPresent 1
      set $firstround 0
    fi
    # for safety, update all timers
    set $latestTime   timestamp-diff beginTime           now
    set &totalTime    timestamp-diff experimentBeginTime now
  while-end
  ##
  ## --------------------------------------------------------------------
  ##
  if &totalTime >= &TOTAL_EXP
    end tasklist
  fi
  ##
  ## now show feedback (1 second) -- officially, there is no feedback except static number 
  ##
  if $firstround = 0 ## the first time it is called you do not need to clear previous number shown
    clear -1
  fi
  if $outcome = 1 ## this means it is correct
    show text $rtSinceStimulusOnset 0 0  &staticRedChannel &staticGreenChannel 0 ## here you can choose color (officially it is yellow)
    set &&correctRTs append $actualRT
  fi
  if $outcome = 2 ## pressed too early
    set &nCommissions increase # we keep a running count of pressing too early
    if &showDetailedFeedback = 1
      show text "ERROR" 0 0 red
      font regular
      show text "Click the mouse or touch the screen only after the yellow numbers appear" 0 200 yellow
    fi
  fi
  ## if no key was pressed, it is a lapse, but you officially not give feedback
  ## lapses can have been detected earlier (late response rather than no response at all)
  if $keypressed = 0 or $outcome = 3
    set &nLapses increase # we keep a running count of pressing too late
    set $outcome 3
    if &showDetailedFeedback = 1
      show text "TOO SLOW" 0 -200 red
      font regular
      show text "TOO SLOW. Touch screen or click mouse within half a second after the yellow numbers appear" 0 200 yellow
    fi
  fi
  delay 1000 # this is the official time the feedback should be shown
  set $tmpLength &&correctRTs size
  ## keep track of averageRT so far in trials
  if $tmpLength > 0
    set &averageRT &&correctRTs roundmean
  else
    set &averageRT 0 # this happens if there are not yet any correct RTs
  fi
  save TRIALCOUNT $outcome $randomDelay &totalTime $rtSinceStart $actualRT &averageRT &nTrials &nLapses &nCommissions

task feedback
  font regular
  set %tmptext "Your average response time in correct trials was " &averageRT " milliseconds."
  show text %tmptext 0 -300
  set %tmptext "There were " &nTrials " trials." 
  show text %tmptext 0 -200
  set %tmptext "You responded too slowly (> 500 ms) " &nLapses " times."
  show text %tmptext 0 -100
  set %tmptext "You responded too early " &nCommissions " times."
  show text %tmptext 0 0
  show text "Click mouse to end this task" 0 100
  readmouse l 1 99999

block test
  message instructionsPVTBtouch mouse
  task pvtb 99999 ## unlimited, because the task itself stops this after 3 (PVT-B) or 10 (PVT) minutes

block feedback
  task feedback 1