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
  • Introduction to the do trial command

    The key thing in psychological experiments is control over stimuli and responses. After reading this section you understand how PsyScript controls the events of a trial and you will be ready to learn how to generate the event sequence you need for your experiments.

    In Psyscript you execute a trial by calling do trial followed by a simple string of text symbols describing the events you want in the trial.

    Each event has its own symbol: for instance the symbol to wait for some time is "#" followed by the number of milliseconds you want to wait for.

    So to do a trial that consisted of waiting for 100 msecs, you would say

    do trial " #100 "

    A trial is simply a list of events like this. For instance, to start the reaction time clock, you write "!t". To erase the screen, you type "!e". There is much more that you can do, but already you know enough to impress yourself.

    Copy (or type) this into Script Debugger or Script Editor (If you don't know where your script editor is, find it using Sherlock.)

    tell application "PsyScript"
       
    activate
       
    reset all
       
    begin experiment
       
    do trial " + #500 'Hello world - I just did this myself' !t "
       
    end experiment
    end tell

    nb: When you hit compile, you may be asked to find Psyscript if it is not already running

    You can run this script to see how it works. You will see a fixation cross for half a second, followed bythe hello world phrase in the centre of the screen. This will remain until you press any key to complete the trial.

    I snuck a couple of new things in there. The "+" sign is the code for a fixation point - pretty easy. By putting the phrase "Hello world - I just did this myself" inside single quotes, I forced it to be treated as one word and displayed as such.

    What if you want to show that phrase some particular place? Easy. Change the do trial line in your script to read like this:

    do trial " + #500 'Hello world - I am in the top left'(250 300) !t " --it will be shown centred 250 pixels in from the left and 300 down from the top of the screen

    What if you want to show those words one at a time? Easy.

       do trial " + #500 I #500 just #500 did #500 this #500 'press any key' !t "

    Can you guess what will happen? each word will display for half a second. Type it into your script and run it to see what happens.

    See the problem? The screen is not being erased between words. In PsyScript, you describe explicitly every event you want to occur, including erasing the screen, and starting the reaction timer.

    We can easily erase the screen after each word:

       do trial " + #500 I #500 !e just #500 !e did #500 !e this #500 !e 'press any key' !t "

    Let's start using AppleScript better.

    A key insight to PsyScript is the idea of storing information in variables. Read this script, maybe think what it might do, then run it from the script editor:

    tell application "PsyScript"
       
    activate
       
    begin experiment
       
    set myTrial to " Hello #500 !e Good-bye !t "
       
    do trial myTrial
       
    end experiment
    end tell

    You can see that we have learned: We can set a variable to hold our trial string so we don't have to type it over and over and so it is quickly changed. You have just made a "trial template"

    The advanced power of do trial with variables

    Nearly always all the trials of an experiment are similar to each other, but sucessive trials vary in their specific contents. In PsyScript, this is done by coding for the variable trial elements using a "?" symbol and then passing the value for the variable into the do trial event on each trial.

    Let's take the example of a trial which shows a word for 500 msecs and then masks it and waits for a response. This is described in the following template:

    set myTrial to " !e ?theWord #500 !e '####' !t "

    What we need now is for "?theword" to be replaced by a real stimulus word on each trial.

    Now you can call the trial template, and pass in the stimulus word using the given parameter

    do trial myTrial given {theword:"dog"}
    do trial myTrial given {theword:"cat"}

    PsyScript will replace "?theword" with "dog" on the first trial, and then cat" on the next trial. Try it out:

    tell application "PsyScript"
       
    activate
       
    begin experiment
       
    set myTrial to " !e ?theWord #500 !e '####' !t "
       
    do trial myTrial
       
    end experiment
    end tell

    nb: see how "dog" is nested inside a squiggly brackets? the given parameter of do trial expects a LIST

    Here's another example:

    wildcard.png

    Of course, in most experiments, you have a list of trials: and list processing is what PsyScript excels at.

    tell application "PsyScript"
       
    activate
       
    begin experiment
       
    set myTrial to " !e + #1000 !e !v ?theWord #500 !e '####' !t "
       
    set trialList to {{" dog "}, {" cat "}}
       
    repeat with myWord in trialList
          
    do trial myTrial given {theWord:myWord}
       
    end repeat
       
    end experiment
    end tell

    This script will iterate through trialList showing each stimulus in succession

    Well, you can do a lot of great stuff now. Plus, there is lots more you can do with trial syntax. From here, you can go to the trials reference section of the manual or check out some advanced examples here.

    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