Note: This file is included in the PsyScript distribution: you can find it in the scripts folder inside demos
You can run it from there, or open it in script debugger to play with it and make changes.
activate -- PsyScript needs to be the front-most app to run an experimentend tell
reset all -- get back to defaults in case a previous experiment has left things set strangely
begin experiment -- this tells psyscript to take control of the screen
-- load function libraries
set fileHelper to load script file ("" & Psyscript base folder & " libraries:file.lib ")
-- this loads a script object full of helpful handlers
-- now we call two of the handlers we just loaded
tell fileHelper to initialize ()
tell fileHelper to createNewSubjectID () -- this function prompts you for a subject ID and prepares a file to store data.
set background color to blue -- in addition to predefined names like this, you can use {R,G,B} lists (black is {0,0,0}, white is {65000,65000,65000}
load permanent stimulus " blacksquare.gif " as picture stimulus name " blk " -- we just loaded a stimulus into memory (from the picture folder)
load permanent stimulus " whitesquare.gif " as picture stimulus name " whitepatch " -- the "name" element is what we will use to refer to the image in trial lines
display dialog " Keyboard or Mouse input? " buttons {" Keyboard ", " Mouse "} default button 2 with icon note
-- just for fun I am giving a choice of input.
if button returned of result is " Mouse " thenset response type to mouse response -- accept mouse clicks as responseselse
set noticed of click area 1 to true -- accept clicks inside this area only
set bounds of click area 1 to { 0 , 0 , 800 , 800 } -- this is a nice big area specified as top, left, bottom, right coordinates
set instructionString to " You will have to click somewhere to end each trial "
set theTrialString to " !a !e #50 !v ëwhitepatch(50 400) !v !t(10000) #1000 'click somewhere' #5000 !e "
-- show the pointer, erase the screen, wait a short time, wait for a refresh, show the "whitepatch image at location x=50, y= 400, wait for a response (time out after 10 secs)set response type to keyboard responseend if
set noticed of every key to false
set noticed of key " Y " to true
set noticed of key " N " to true
set mapping of key " Y " to " Yes "
set mapping of key " Y " to " No "
set instructionString to " You will have to press ¯yå or ¯nå to end each trial "
set theTrialString to " !a !e #50 !v ëwhitepatch(50 400) !v !t(10000) #1000 'press y or n' #5000 !e "
-- show the pointer, erase the screen, wait a short time, wait for a refresh, show the "whitepatch image at location x=50, y= 400, wait for a response (time out after 10 secs)
display instructions instructionString & return & " press space to continue "
repeat 2 timesdo trial theTrialString -- show the trial string we defined aboveend repeat
tell fileHelper to writespreadsheet ({ reaction time , subject response }) -- add some response data to our output file. you would normally store trial parameters as well.
end experiment -- allows psyscript to clean up
activate -- PsyScript needs to be the front-most app to run an experiment
this brings PsyScript to the front. PsyScript can operate while not being the front most app, but cannot draw to the screen unless it is frontmost (so it has full control over the screen).
reset all
If a different experiment has been run previously, this command will remove any settings (such as voice key input, or keys re-mapped)
begin experiment -- this tells psyscript to take control of the screen
Beginning the experiment is required before any trials occur- it allows PsyScript to draw to the screen. You can set many of PsyScript's variables prior to beginning the experiment, but it is easy to get it out oath way early.
Note: if PsyScript terminates before the ending the experiment, it will leave the screen blank. This looks like a crash, but just use the application switching key (cmd-tab by default) to get back to the script editor or other apps.
Note: You can send PsyScript an "end experiment" event to get back to normal behaviour
set fileHelper to load script file ("" & Psyscript base folder & " libraries:file.lib ")
PsyScript does not have built in functions for many common events such as list processing or file handling. However, I have provided some handy libraries of handlers to do this for you. You can also extend these or create your own.
tell fileHelper to initialize ()
Here we call one of the handlers from the library we just loaded.
The initialize handler initializes some path properties so that PsyScript knows where to look for images (the Resources folder beside your script).
tell fileHelper to createNewSubjectID () -- this function prompts you for a subject ID and prepares a file to store data.
Another handler from the library. This one prompts the experimenter for a subject ID, verifies that is is unique (or asks for another ID), then initializes a file for storing results
Note: we could have called this as createNewSubjectID() of fileHandler
Advanced: You could modify or create a new handler to store data into a single file, or even a database.
set background color to blue -- in addition to predefined names like this, you can use {R,G,B} lists (black is {0,0,0}, white is {65000,65000,65000}
Here we set the background color. This is an element of the Application property of PsyScript. I used one of the defined colors by name, but I caudal have said {0,0,65000} in RGB (red, green, blue) notation. All colors in PsyScript are like this.
We can also set the word font, word size, etc. See the dictionary by dropping PsyScript on top of your script editor.
You would also set the screen size, and color depth here.
load permanent stimulus " blacksquare.gif " as picture stimulus name " blk " -- we just loaded a stimulus into memory (from the picture folder)
load permanent stimulus " whitesquare.gif " as picture stimulus name " whitepatch " -- the "name" element is what we will use to refer to the image in trial lineshere we loaded two stimuli from the Resources folder beside our script. As permanent stimuli, they are stored in memory and are very quick to access
display dialog " Keyboard or Mouse input? " buttons {" Keyboard ", " Mouse "} default button 2 with icon note
-- just for fun I am giving a choice of input.This uses a dialog supplied by Apple's standard additions. You get back what the user entered in the result variable. Again, learn about this by examining the Standard Scripting additions dictionary.
if button returned of result is " Mouse " then
set response type to mouse response -- accept mouse clicks as responses
This tells PsyScript to expect responses from the mouse.
Note: the possible response types are keyboard response/mouse response/reply response/sound response/vtrig response/combo response/bbox response
set noticed of click area 1 to true -- accept clicks inside this area only
set bounds of click area 1 to { 0 , 0 , 800 , 800 } -- this is a nice big area specified as top, left, bottom, right coordinatesBecause we are using the mouse as input, we need to define a click area that is noticed so that responses can be noticed and recorded into subject response. We should also set the click mapping to a meaningful label, like :"top left"
set instructionString to " You will have to click somewhere to end each trial "
Here I have just set a variable to store my instruction string.
set theTrialString to " !a !e #50 !v ëwhitepatch(50 400) !v !t(10000) #1000 'click somewhere' #5000 !e "
Here we define the events that will occur on each trial. This is not a trial, we have merely defined a variable to hold the trial event string so we don't have to type it over and over.
else
set response type to keyboard responseend if
set noticed of every key to false
set noticed of key " Y " to true
set noticed of key " N " to true
set mapping of key " Y " to " Yes "
set mapping of key " Y " to " No "
set instructionString to " You will have to press ¯yå or ¯nå to end each trial "
set theTrialString to " !a !e #50 !v ëwhitepatch(50 400) !v !t(10000) #1000 'press y or n' #5000 !e "
This is the alternative set of actions to take if the user chose keyboard response. The first line tell PsyScript to ignore all key presses, then we selectively turn on the keys we are using, also setting meaningful mappings.
Note: PsyScript supports the "object model", so you can always say "some key" or "every key" or every key whose mapping is ""
display instructions instructionString & return & " press space to continue "
Display instructions allows us to simply display text on the screen.
Note: You can also supply a file name instead of text. This is useful if you have long instruction strings, or if you make a script that is re-purposed by different stimulus and instruction files.
repeat 2 times
This is an AppleScript repeat loop
do trial theTrialString -- show the trial string we defined above
Here is where we actually do the trial, finally ;-)
PsyScript executes each of the events it finds in the string which we stored in trialString
tell fileHelper to writespreadsheet ({ reaction time , subject response }) -- add some response data to our output file. You would normally store trial parameters as well.
Another handler we get in file.lib
This one can take a string, a list, or a list of lists, and writes them to the file set by createNewSubjectID.
Advanced: in fact it writes to the file path stored in pSubjectDataFile. You could set this yourself to point to any file you like.
end repeat
end experiment -- allows psyscript to clean uphere the trial repeat is finished, and then we say end experiment, so that PsyScript lets go of the screen
end tell
This ends the script
| MACCS | |
Documentation | Downloads | FAQ | Mailing List | Last change: echo date( "F d Y.", getlastmod() ); ?> |
| Advanced Search |