PsyScriptIcon.png PsyScript: getting experiments done

$query\n"; } $result = mysql_query($database, $query, $connection) or die("ack! query failed: " ."
  • errorno=".mysql_errno() ."
  • error=".mysql_error() ."
  • query=".$query ); return $result; } $Base = "http://www.maccs.mq.edu.au"; $URL= $PHP_SELF; $connection = mysql_connect('localhost', 'tim', 'connect2'); if (!$connection) { print("Cannot connect to database. Call Tim.
    "); exit(); } $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $ChkBase=$row[0]; $ChkURL=$row[1]; $ChkCount=$row[2]; $Count=$ChkCount; } if ($ChkURL == ""){ safe_db_query("Counters","INSERT INTO Count VALUES ('$Base','$URL','0')", $connection); $Count=0; } $Count++; safe_db_query("Counters","UPDATE Count SET Number='$Count' WHERE Base='$Base' AND URL='$URL'"); $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $Base=$row[0]; $URL=$row[1]; $Count=$row[2]; } echo $Count; */ ?>hits
  • Trial String Examples

    Example Trials

    How do I ...

    Trial String examples

    These are adapted from the excellent examples page given by Pepper Williams in his guide for RSVP, (the basis for trial string syntax in PsyScript).

    Example 1

    The simplest possible experiment probably involves just showing an image or word in the center of the screen, following an intertrial-interval and a briefly-presented fixation cross:

    set trialEvents to "!e #1000 + #500 ?1 !t"

    do trial trialEvents given {"@penguin"}

    do trial trialEvents given {"PENGUIN"}

    !e

    erase the screen
    #1000 pause for 1000 ms (intertrial interval)
    + show the fixation cross in the center of the screen
    #500 pause for 500 ms (while subject fixates)
    ?1 wildcard character — replaced by @penguin in the first trial, drawing a Pict, and 'PENGUIN' in the second trial, drawing a word
    !t start the reaction time timer

    nb: using the @ sign to denote an image is a bit confusing (to me at least), so I would handle this as:

    set imageTrial to "!e #1000 + #500 @?1 !t"

    set wordTrial to "!e #1000 + #500 ?1 !t"

    do trial wordTrial given {"penguin"}

    do trial imageTrial given {"penguin"}

    Example 2

    In the last setup, the stimuli were loaded and shown “online”; this will take time and thus lengthen the fixation duration. Also, the draw operation might take longer than one screen refresh, causing “flicker” as the stimulus is drawn. In the next example, we'll preload the stimulus and use the !h/!u trial events to make stimulus presentation instantaneous.

    set trial_events "!e #1000(?1) + #500 !e !h #100(*1) !v !u !t"

    do trial trial_events given {"@penguin"}

    do trial trial_events given {"penguin"}

    !e erases the screen as before. "#1000(?1)" pauses for 1000 ms (intertrial interval), and during the pause, preloads the stimulus specified in the wildcard. Afte the fixation cross ("+") is shown for 500 msecs (#500) and then erased ("!e"), we hide the screen (!h),or freeze it, so we can build a compelx dispaly without showing it before it is compelted, then, during a 1msec pause ("#100(*1)"), we draw the first (and in this case only) pre-loaded stimulus. "!v" tells us to wait for the monitor to vertsynch then we "!u" to unhide the screen, revealing the new drawing to the viewer. "!t" starts the reaction time timer as usual.

    Timing will be more exact and imaes will dispaly more “crisply” with this event sequence than with the last. However, you should get valid reaction times with either sequence, so in most experiments it won't make too much difference which one you use. For simplicity, in most of the remaining examples I'll preload Pict stimuli but I won't bother with the !h/!u/!v commands.

    nb: if your machine is quick enough, probably just adding a !v call in front of the image is sufficient to get it to load without tearing (i.e., you may not need to hide and unhide the screen. Preloading is nearly always essential

    Example 3

    Now let's say we want to show a picture with an identifier underneath, for example to get subjects to associate the word with the picture.

    set trial_events "!e #1500(@?image) + #750 *1 '?label'(320 400) !t"

    do trial trial_events given {image:"penguin", label:"Chilly Willy"}

    Event Sequence:

    !e

    Erase the screen

    #1500(@?image)

    Pause for 1500 ms, loading the first wildcard

    +

    Show the fixation cross in the center of the screen

    #750

    Pause for 750 ms (while subject fixates)

    *1

    Draw the first (and in this case only) pre-loaded stimulus

    ?label(320 400)

    Draw the second wildcard-specified stimulus, at near the bottom center of the screen

    !t

    Start the reaction time timer

    Example 4

    Now let's look at how to do feedback trials. In the next example, we have a “test trial,” where the subject makes a response, then if the response is incorrect (let's say we defined "L" as the correct response key), there's a “feedback trial” that plays the “buzz” sound and gives the correct response. The test trial is exactly like Example 1, so we describe only the feedback trial.

    set pos1 to{320,400}

    set trial_events to "!e #1000 + #500 @?image !t"

    set feedbackString to"$buzz 'That was a ?label'(?pos1) !t(2000)"

    do trial trial_events given {image:"penguin"}

    if subject response is not "L" then do trial feedbackStringgiven {label:"PENGUIN",pos1:pos1}

    "$buzz" sound will load and play (this is one of the sounds provided in the PsyScript program).

    In the section reading " 'That was a ?label'(?pos1)' ", The wildcard values of label and pos1 will replace the wildcard markers specified in the trial, so the viewer will see “That was a PENGUIN” drawn in the bottom center of the screen.

    "!t(2000)" starts the reaction time clock, timing-out after 2000 ms (i.e., PsyScript wait at most 2 seconds before proceding onto the next trial.

    There are a couple things to note here. First, no !e command is issued at the beginning of the feedback trial, so the picture from the test trial will remain on the screen and “That was a PENGUIN” will be drawn below the Pict.

    back_f01.gif

    Example 5

    This example shows how to give the accuracy and reaction time of the previous trial in a feedback trial using a more general method


    tell application"PsyScript"

    activate
    begin experiment
    set trial_events to"!e #1000 + #500 ?1 !t"
    set good response to"p"
    do trial trial_events given {"penguin"}
    my giveFeedback ()
    end experiment
    end tell

    on giveFeedback()
       
    tell application "PsyScript"
          
    set theRT to reaction time
          
    set fb_trial to "!w(20 30) ?1; Response Time: ?2 ''(0) !t(2000)"
          
    if (subject response = good response) then
             
    do trial fb_trial given {"CORRECT", theRT}
          
    else
             
    do trial fb_trial given {"INCORRECT", theRT}
          
    end if
       
    end tell
    end giveFeedback

    "!w(20 30)" Tells PsyScript to enter wrap mode and start the next word at position x=20, y=30

    Because we are in word wrap mode, all single words will be drawn with a space between them instead of occuring on top of each other as normally happens without specifying a position. You can control what character (if any) is drawn bettwen words in word wrap mode by setting the word wrap delimiter application property

    "?1" Draws the word specified in the wildcard, so the function fills in “CORRECT” if the subject was correct on the previous trial, “INCORRECT” otherwise.

    Response Time Draw the words “Response” & "Time"

    ?2 will write the value of the variable reaction time, which holds the RT of the previous trial

    ''(0) (two single quotes) Tells PsyScript to draw an empty string in the center of the screen; it's necessary here to get out of “wrap” mode. If we didn't include this, the fixation cross on the next trial would get drawn to the right of the response time.

    !t(2000) Start the timer; timeout after 2000 ms

    back_f01.gif

    Example 6

    This example shows how to calculate the average accuracy for a whole block of trials, then show the performance level to the subject after the block.


    tell application"PsyScript"

    activate
    begin experiment

    set trialEvents to"!e #1000 + #500 @?image !t"
    set feedbackTrial to"!e 'Accuracy rate (percent):'(320 210) ?1 !t(2000)"

    (* First, zero two variables which we will use as counter *)
    set acc_trials to 0
    set total_trials to 0

    (* Now, do your block of trials. *)
    repeat with aStim in {"penguin", "lion", "tiger"}
    do trial trial_events given {image:aStim}
    set total_trials to total_trials + 1
    if subject response is "L" then set acc_trials to acc_trials + 1
    end repeat

    (* Now you calculate the accuracy and do the feedback trial *)
    set acc_percent to acc_trials / total_trials * 100
    do trial fb_trial given {acc_percent}
    -- that's it!
    end experiment

    end tell

    A more realistic example would have different response keys for correct and incorrect responses

    repeat with aStim in {{"penguin","L"}, {"lion","T"}, {"tiger","L"}}

    set theStim to contents of item 1 of aStim

    set correctResp to contents of item 2 of aStim

    do trial trial_events given {image:theStim}
    set total_trials to total_trials + 1
    if ((get subject response) = correctResp) then set acc_trials to acc_trials + 1

    end repeat

    If you develop useful trial examples and want to share them with the PsyScript community, e-mail your scripts to me (tim@maccs.mq.edu.au) and I'll post them on the PsyScript web page.

    How Do I ...

    How do I display a picture as instructions

    The easiest way is to use a trial string like

    do trial "@?instructionPicture #b !t(0)" given {instructionPicture:"Name_of_your_file.png"}

    This will load the file and display it, then wait for a space-bar press.

    back_f01.gif
    MACCS PsyScriptIcon.png Documentation Downloads FAQ Mailing List
    Last change:
    Advanced Search

    Applescript in a Nutshell : A Desktop Quick Reference

    AppleScript for Applications: Visual QuickStart Guide

    AppleScript For Dummies

    Applescript for the Internet Visual Quickstart Guide

    Applescript Language Guide; English Dialect

    Danny Goodman's Applescript Handbook