Top Banner
1 of 69 Code Script Exercises (1- Script Exercises (1- 10) 10) Code for Experiments Code for Experiments E-Prime 2002 Workshop E-Prime 2002 Workshop Files on My Documents\My Files on My Documents\My Experiments\Workshop\E-Prime Experiments\Workshop\E-Prime Exercises Exercises Exercises Exercises
69

1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

1 of 69Code

Script Exercises (1- 10)Script Exercises (1- 10)Code for ExperimentsCode for Experiments

E-Prime 2002 WorkshopE-Prime 2002 Workshop

Files on My Documents\My Experiments\Files on My Documents\My Experiments\Workshop\E-Prime ExercisesWorkshop\E-Prime Exercises

E-Prime Script ExercisesE-Prime Script Exercises

Page 2: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

2 of 69Code

E-Prime Code TutorialsE-Prime Code Tutorials1. Use of help facility.2. Use of Code to Set a Property.3. Program flow control.4. Use of Code to Set the Stimulus Conditional on a List

Attribute.5. Using Debug.Print to Report Event Times and debugging.6. Use of code to provide cumulative data and exit block when

five correct answers in a row. (Optional).7. Using code to read a digital IO bit and set digital bit (optional).8. Use of Onset Synch to control external hardware (optional). 9. Use of loop to present frames (optional).10. Sample data from a list and delete repeats (optional).

Page 3: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

3 of 69Code

Basic Steps to Writing Basic Steps to Writing CodeCode

 

1.   Determine what you want your code to do and at what point in the experimental procedure it is to occur. [e.g., if you want to set the stimulus to a random number from 1-499, “c.SetAttrib "Stim", Random(1,499)”]

2.   Declare any variables that maintain information across multiple executions in the User Code area (display the Script window via the View menu, and select the User Tab). If the variables must be initialized to other than the default values, add an Inline object to the start of the experiment procedure for initialization (e.g., declare an array of real numbers Dim Word(10) As String)

3.   Add Inline objects at the appropriate procedure (e.g., session, block, trial) and position in the procedure to execute the code, declare local variables not referenced by other objects, and enter your procedural code.

4.   Reference any variables in the List objects (in the experimental context) with c.GetAttrib to get the values and c. SetAttrib to set the values of the variables. Set properties of objects (e.g, TextDisplay.x=0), or execute objects (e.g., TextDisplay.run). Query properties of other objects as needed (e.g., localvariable=Bitmap.RT).

5.   Reference results of the code by using attributes in other E-Prime objects (e.g., add “[AttributeName]” to the text area of a TextDisplay object).

6.   Include any debug related printing using the Debug.Print option to check data. In the View menu, select Output, and select the Debug tab. To report when things happened, add “Cstr(Clock.Read) to get the time in milliseconds since the beginning of the experiment.

7.   Run the experiment, checking the debug output.

Page 4: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

4 of 69Code

Exercise 1: Using E-Basic Online Exercise 1: Using E-Basic Online HelpHelp

The are over 1000 pages of online help The are over 1000 pages of online help for E-Basic. Use the help to find for E-Basic. Use the help to find commands, learn their syntax, and get commands, learn their syntax, and get examples on how to use the examples on how to use the commands. commands.

This short example will show how to find This short example will show how to find a command (Display.Rectangle) copy a command (Display.Rectangle) copy an example and run it and how to find an example and run it and how to find things in the E-Basic Help. things in the E-Basic Help.

Page 5: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

5 of 69Code

1. Open a new 1. Open a new Experiment in E-StudioExperiment in E-Studio

2. Create an InLine 2. Create an InLine object for later use in object for later use in example to copy code example to copy code to. Click and drag the to. Click and drag the Inline Object to the Inline Object to the SessionProc SessionProc

3. Open Help, Click the 3. Open Help, Click the Help Menu select E-Help Menu select E-Basic Help.Basic Help.

4. Scroll through the list 4. Scroll through the list of commands, go to the of commands, go to the Display:GraphicsDisplay:Graphics

Opening E-Basic HelpOpening E-Basic Help

Page 6: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

6 of 69Code

Select Command, Examine Select Command, Examine HelpHelp

5. Click on 5. Click on “Canvas.Rectangl“Canvas.Rectangle (method)”e (method)”

6. Examine the 6. Examine the help. Check the help. Check the Syntax, Syntax, Description, Description, Comments, Comments, Example, and See Example, and See AlsoAlso

Page 7: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

7 of 69Code

Copy Example From HelpCopy Example From Help 7. Copy the 7. Copy the

example into the example into the copy buffercopy buffer Move cursor to Move cursor to

beginning of beginning of ‘This sample.. ‘This sample.. Move cursor to Move cursor to end example end example

Click and drag to Click and drag to the end of the the end of the example (it will example (it will reverse highlight reverse highlight the text)the text)

Copy the Copy the example with example with Ctrl-C or Right Ctrl-C or Right click/copy click/copy

Page 8: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

8 of 69Code

Paste Example Into Paste Example Into ExperimentExperiment

8. Open the Inline object, paste (type Ctrl-V) the text into the inline 8. Open the Inline object, paste (type Ctrl-V) the text into the inline objectobject

9. Check that all lines copied completely, (note first and last lines 9. Check that all lines copied completely, (note first and last lines should be green comment lines)should be green comment lines)

10. Run the example it should put up a green square10. Run the example it should put up a green square

DisplayDisplay

Page 9: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

9 of 69Code

Modify ParametersModify Parameters 11. To learn 11. To learn

parameters it is good parameters it is good to change some of the to change some of the parameters to see if parameters to see if they do what is they do what is expected. Change:expected. Change: width w= 600width w= 600 pen color to redpen color to red pen width to 40pen width to 40

12. Rerun experiment12. Rerun experimentDisplayDisplay

The example is in the exercises with The example is in the exercises with the file name #CodeExercise1-the file name #CodeExercise1-Help.esHelp.es

Page 10: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

10 of 69Code

E-Basic Help - Table of ContentsE-Basic Help - Table of Contents

13. Open E-Basic help13. Open E-Basic help 14. Select Help Topics14. Select Help Topics 15. Click Contents tab, 15. Click Contents tab,

look at contents for look at contents for alphabetic list of alphabetic list of commandscommands Note if you double click Note if you double click

on E-Basic and click on E-Basic and click Welcome you get the Welcome you get the command summarycommand summary

Double click on other Double click on other topics to expand the topics to expand the listings and browse the listings and browse the table of contents of the table of contents of the commands.commands.

The Contents allows you to browse the help. It is particularly The Contents allows you to browse the help. It is particularly helpful for identifying summaries of commands and families of helpful for identifying summaries of commands and families of commands. commands.

Page 11: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

11 of 69Code

E-Basic Help - IndexE-Basic Help - Index

16. Use the Index to 16. Use the Index to get the specific topic, get the specific topic, Click Index, type Click Index, type Special KeysSpecial Keys double double click topic or press click topic or press displaydisplay

17. Look at special 17. Look at special keys listing of how to keys listing of how to enter keys such as enter keys such as the {ANY}. Scroll the {ANY}. Scroll through to view List through to view List of special keysof special keys

The Index allows you to find specific commands when you know The Index allows you to find specific commands when you know the name of the command or function. the name of the command or function.

Page 12: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

12 of 69Code

E-Basic Help - FindE-Basic Help - Find

18. Select the Find 18. Select the Find Help option.Help option.

19. Search for the 19. Search for the crespcresp – correct – correct response designation.response designation.

20. Open up the 20. Open up the specification. specification.

The Find allows you to find any reference to a string. For The Find allows you to find any reference to a string. For example a parameter of a function may not be in the index but a example a parameter of a function may not be in the index but a Find will locate the help pages that include that string. Find will locate the help pages that include that string.

Page 13: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

13 of 69Code

Help Exercise SummaryHelp Exercise Summary Use the online help.Use the online help. When needing a given type of command use When needing a given type of command use

the Contents under the Topic E-Basic the Contents under the Topic E-Basic Welcome.Welcome.

Use the Index for finding commands of Use the Index for finding commands of interest when you know the name.interest when you know the name.

Use the Find if the topic is not in the index Use the Find if the topic is not in the index but you know a related term.but you know a related term.

For new commands it is a good practice to For new commands it is a good practice to copy the example and run it stand alone copy the example and run it stand alone before trying to use it in new functions. before trying to use it in new functions.

Page 14: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

14 of 69Code

Code Exercise 1 Study Code Exercise 1 Study QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Use the Help to find how to declare an Use the Help to find how to declare an integer type variable?integer type variable?

2.2. Find the syntax and an example of the IF Find the syntax and an example of the IF command? command?

3.3. Find a command that examines a Find a command that examines a command which would allow you to pick a command which would allow you to pick a member of a text string member of a text string “red,green,blue,black” with an index to “red,green,blue,black” with an index to pick the correct word? pick the correct word?

4.4. Determine how to exit a subroutine early?Determine how to exit a subroutine early?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 15: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

15 of 69Code

Code Exercise 2: Use of Code to Set a PropertyCode Exercise 2: Use of Code to Set a Property

With code you can directly set properties of allowing great flexibility by setting and varying the stimuli. This is a simple example of adding code to display the stimuli in a random location along the x-axis.

Page 16: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

16 of 69Code

Use of Code to Set a Use of Code to Set a PropertyProperty

1. Open #CodeExercise2-SetProperty.es (My 1. Open #CodeExercise2-SetProperty.es (My Documents\My Experiments\Workshop\E-Documents\My Experiments\Workshop\E-Prime Exercises\)Prime Exercises\)

2. Run the experiment, notice the random 2. Run the experiment, notice the random placement of the stimuli on the screenplacement of the stimuli on the screen

Page 17: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

17 of 69Code

Edit StimPosition CodeEdit StimPosition Code 3. Open the 3. Open the StimPositionStimPosition Inline Inline

object and edit the program to object and edit the program to randomly present stimuli along the y-randomly present stimuli along the y-axisaxis

BeforeBefore

AfterAfter

Page 18: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

18 of 69Code

Run And Test ProgramRun And Test Program 4. Run and test the program4. Run and test the program

5. Save as CodeExample2.es5. Save as CodeExample2.es

Page 19: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

19 of 69Code

Looking Up Properties Of An Looking Up Properties Of An ObjectObject

6. Examine the 6. Examine the properties properties window of the window of the Probe object in E-Probe object in E-Studio. This Studio. This illustrates most illustrates most of the properties of the properties and how they are and how they are set set If not open open If not open open

the properties the properties windowwindow

Scroll through Scroll through the propertiesthe properties

Determine Determine default value of default value of the font sizethe font size

Page 20: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

20 of 69Code

Getting Help On Object Getting Help On Object PropertiesProperties

7. You can get 7. You can get documentation on documentation on the properties either the properties either in the E-Prime in the E-Prime Reference manual Reference manual or the Help topicsor the Help topics Open the Help Open the Help

topicstopics Select Text Display Select Text Display

Object Properties Object Properties WindowWindow

Page 21: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

21 of 69Code

Examine Properties Set Examine Properties Set FontSizeFontSize

8. Examine the 8. Examine the properties specificationproperties specification

9. Add a command Set 9. Add a command Set the font size to vary in the font size to vary in units of 20 points units of 20 points randomly from 20 to 100 randomly from 20 to 100 pointspoints

Page 22: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

22 of 69Code

Use Item Function to Choose Use Item Function to Choose OptionOption

10. Setting a property with the Item function. Often 10. Setting a property with the Item function. Often there is a need to choose items from a set of items. there is a need to choose items from a set of items. This is illustrated by selecting the FontNameThis is illustrated by selecting the FontName Use Item$ function to choose the font from a list of Use Item$ function to choose the font from a list of

itemsitems Add a command to randomly choose the FontName Add a command to randomly choose the FontName

11. Run the program examine font size and type11. Run the program examine font size and type

Page 23: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

23 of 69Code

Setting Yes/No Explicit List Setting Yes/No Explicit List PropertiesProperties

11. Set the FontItalic function off/on by selecting 0/111. Set the FontItalic function off/on by selecting 0/1 12. Select the color from a list, chose color function 12. Select the color from a list, chose color function ccolorccolor. .

The function coverts a string containing a color name to the The function coverts a string containing a color name to the

red, green, blue values for the color. (If you click on the red, green, blue values for the color. (If you click on the ForeColor properties you can see the list of color names). Run the ForeColor properties you can see the list of color names). Run the program.program.

Some properties must be set, not as text but as on/off values or through Some properties must be set, not as text but as on/off values or through calls to special functions. For on/off, the value of 1 and 0 are used. calls to special functions. For on/off, the value of 1 and 0 are used. The ForeColor property is an example of a property that needs a The ForeColor property is an example of a property that needs a function to covert names to values (e.g., red, green, blue) for the color. function to covert names to values (e.g., red, green, blue) for the color.

Page 24: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

24 of 69Code

Setting 8 Properties of a Text DisplaySetting 8 Properties of a Text Display

13. Examine this example. It sets 8 13. Examine this example. It sets 8 parameters representing 57600 parameters representing 57600 (4x4x5x2x2x3x6x10) possible possible (4x4x5x2x2x3x6x10) possible possible variations of the stimulus in 8 lines of code. variations of the stimulus in 8 lines of code. (Note this is example (Note this is example

#CodeExercise2-#CodeExercise2-SetPropertyMulitpleParameters.es)SetPropertyMulitpleParameters.es)

Page 25: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

25 of 69Code

Code Exercise 2 Properties Study Code Exercise 2 Properties Study QuestionsQuestions

Could you at this point set properties of Could you at this point set properties of objects?objects?

1.1. Change the font to bold? Change the font to bold?

2.2. Change background colors of the display? Change background colors of the display?

3.3. Set the X position of the Fixation display to Set the X position of the Fixation display to be the same as the Probe? be the same as the Probe?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 26: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

26 of 69Code

Exercise 3 Execution ControlExercise 3 Execution Control

Execution flow control allows repetitive Execution flow control allows repetitive actions or conditional actions. In this actions or conditional actions. In this example we will use a example we will use a For For statementstatement for a repetitive action and an for a repetitive action and an IF IF statement for conditional actions. statement for conditional actions.

If x > 10If x > 10

ActionActionTrueTrue

ActionActionFalseFalse

For counter For counter = Start to End= Start to End

LoopLoopActionAction

Page 27: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

27 of 69Code

Exercise 3 Execution ControlExercise 3 Execution ControlFor counter For counter

= Start to End= Start to End

If x > 10If x > 10

ActionActionTrueTrue

LoopLoopActionAction

If x > 10If x > 10

ActionActionTrueTrue

Examine the code note the:Examine the code note the: For next loop For next loop IF conditionsIF conditions

The indenting shows the The indenting shows the commands in the for loop.commands in the for loop.

Page 28: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

28 of 69Code

Load and Execute Load and Execute 1. Open 1. Open

#CodeExercise3-#CodeExercise3-ProgramControl.es ProgramControl.es from My from My Documents\My Documents\My Experiments\Experiments\Workshop\E-Prime Workshop\E-Prime Exercises\.Exercises\.

2. Examine the 2. Examine the InLine1 code. Note InLine1 code. Note it is it is #CodeExercise1-#CodeExercise1-Help.es with a For Help.es with a For and If statements. and If statements.

3. Run the program 3. Run the program see the moving boxsee the moving box

Page 29: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

29 of 69Code

Add an IF ThenAdd an IF Then 4. Add the IF Else statements 4. Add the IF Else statements

shownshown If begins the conditional If begins the conditional

executionexecution Then is the true actionThen is the true action Else the False ActionElse the False Action End IF finishes the IfEnd IF finishes the If

Note the comments Note the comments explain the mod explain the mod function to get a function to get a remainder and the remainder and the CColor to set the colorCColor to set the color

Page 30: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

30 of 69Code

Run Program With If Run Program With If ThenThen

5. Run the program. 5. Run the program. Observe the color change. Observe the color change.

6. Change the maximum 6. Change the maximum of the For and add ElseIf of the For and add ElseIf instead of Else for 3 states. instead of Else for 3 states.

Page 31: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

31 of 69Code

Run ProgramRun Program 7. Run program examine results.7. Run program examine results.

8 Save program as CodeExercise3.ex8 Save program as CodeExercise3.ex

Page 32: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

32 of 69Code

Code Exercise 3 Program Control Code Exercise 3 Program Control QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Add a loop to present the square in Add a loop to present the square in #CodeExercise3-ProgramControl to make the #CodeExercise3-ProgramControl to make the square move up for 1000 iterations, down and be square move up for 1000 iterations, down and be a circle for 1000 iterations, and move horizontally a circle for 1000 iterations, and move horizontally and be an oval. and be an oval.

2.2. Find other program control commands and Find other program control commands and implement a While…When, Do…Loop or Case implement a While…When, Do…Loop or Case processprocess..

3.3. Specify how to leave a For loop early (not covered Specify how to leave a For loop early (not covered in exercise but in lecture)in exercise but in lecture)..

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 33: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

33 of 69Code

Code Exercise 4. Use of Code to Set the Stimulus Code Exercise 4. Use of Code to Set the Stimulus Conditional on a List AttributeConditional on a List Attribute

This example uses the “Condition” variable to set the “Stim” variable to a random number and the “Resp” variable to the expected key.

This also checks for errors in the typing of the attributes.

Page 34: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

34 of 69Code

Open Code Examine Get Open Code Examine Get AttributeAttribute

1. Open 1. Open #CodeExercise4-#CodeExercise4-ListAttribute.es from My ListAttribute.es from My Documents\My Documents\My Experiments\Workshop\Experiments\Workshop\E-Prime Exercises\.E-Prime Exercises\.

2. Examine the code and 2. Examine the code and list and predict what list and predict what will occur. will occur.

Page 35: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

35 of 69Code

Run And Check for ErrorRun And Check for Error 3. Run the experiment3. Run the experiment

Note you will see a message box appear Note you will see a message box appear on the last trial to indicate that a coding on the last trial to indicate that a coding error has occurred, hit enter. This is error has occurred, hit enter. This is intentional to illustrate self checking code. intentional to illustrate self checking code.

In this case the Bad Condition = bxlow In this case the Bad Condition = bxlow indicates that a spelling error has been indicates that a spelling error has been detected in the Condition.detected in the Condition.

Page 36: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

36 of 69Code

Correct ErrorsCorrect Errors 5. Open 5. Open List1List1 and edit and edit bxlowbxlow to to

belowbelow..

BeforeBefore AfterAfter

Page 37: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

37 of 69Code

Edit Edit RandomNumberGenerateRandomNumberGenerate

6. Open RandomNumberGenerate and edit the 6. Open RandomNumberGenerate and edit the conditions to select a number for below 1-4, above conditions to select a number for below 1-4, above 6-9. 6-9.

BeforeBefore

AfterAfter

Page 38: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

38 of 69Code

Edit InstructionsEdit Instructions 7. Edit display instructions located on 7. Edit display instructions located on

the Fixation display.the Fixation display.

BeforeBefore

AfterAfter

Page 39: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

39 of 69Code

Run and Test ProgramRun and Test Program 8. Save as CodeExample4.es.8. Save as CodeExample4.es. 9. Run to test the program, note the 9. Run to test the program, note the

random numbers selected are now random numbers selected are now between 1-9.between 1-9.

Page 40: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

40 of 69Code

Code Exercise 4 Attributes Code Exercise 4 Attributes QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Use Code to set the attribute of font color Use Code to set the attribute of font color based on the Condition? based on the Condition?

2.2. Explain the difference in using code to set Explain the difference in using code to set an attribute and setting an attribute and an attribute and setting an attribute and setting the property of the attribute using setting the property of the attribute using the [attribute] syntax?the [attribute] syntax?

3.3. Predict what would happen if an attribute is Predict what would happen if an attribute is set multiple times in the same procedure? set multiple times in the same procedure?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 41: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

41 of 69Code

Exercise 5: Using Debug.Print to Report Event Exercise 5: Using Debug.Print to Report Event TimesTimes

Use the Debug.Print command to write debug data during the running of the experiment to monitor when fast actions occur (e.g., OnsetTime of an object). Note an Object.OnsetTime records when an output event takes place.

The results are shown in the Output window available on the View menu.

Page 42: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

42 of 69Code

Run Debug.Print Exercise Run Debug.Print Exercise 1. Open #CodeExercise5-DebugPrint.es (My 1. Open #CodeExercise5-DebugPrint.es (My

Documents\My Experiments\Workshop\E-Documents\My Experiments\Workshop\E-Prime Exercises\).Prime Exercises\).

2. Run the experiment, note the use of the 2. Run the experiment, note the use of the RandomNumberGenerate code.RandomNumberGenerate code.

Page 43: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

43 of 69Code

View Output WindowView Output Window 3. View Output window located at the 3. View Output window located at the

bottom of the screen. Click on View bottom of the screen. Click on View menu and select Output.menu and select Output.

Page 44: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

44 of 69Code

Copy and Clear Debug Copy and Clear Debug OutputOutput

4. You can copy the output to the copy buffer with a right click 4. You can copy the output to the copy buffer with a right click in the window and copy. You can clear it also with the right in the window and copy. You can clear it also with the right click (otherwise the output is appended). Copy the output click (otherwise the output is appended). Copy the output and paste it into Excel. This is useful for using Excel to check and paste it into Excel. This is useful for using Excel to check timing issues such as the time between stimuli.timing issues such as the time between stimuli. Select all the output with clickSelect all the output with click

start and drag to endstart and drag to end Copy Copy Clear the informationClear the information

5. Open Excel5. Open Excel Select first cellSelect first cell Paste the copied itemsPaste the copied items Calculate onset time to onset timeCalculate onset time to onset time

Onset time enter in Cell F1 Onset time enter in Cell F1

= A2-A1= A2-A1

Page 45: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

45 of 69Code

Edit Debug.PrintEdit Debug.Print 6. Examine and edit DebugPrint note:6. Examine and edit DebugPrint note:

The “\t” puts a tab in the string (which causes tab to new The “\t” puts a tab in the string (which causes tab to new column in Excel spreadsheet in copycolumn in Excel spreadsheet in copy

The & concatenates stringsThe & concatenates strings The _ at the end of a line continues a lineThe _ at the end of a line continues a line

7. Add an output of a Probe.RT to report the response time in 7. Add an output of a Probe.RT to report the response time in the output window.the output window.

BeforeBefore

AfterAfter

Page 46: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

46 of 69Code

View Output WindowView Output Window 5. Run program and view Output 5. Run program and view Output

window, note that the Prob.OnsetTime window, note that the Prob.OnsetTime is now included in the Output window.is now included in the Output window.

6. Save as CodeExample4.es.6. Save as CodeExample4.es.

BeforeBefore AfterAfter

Page 47: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

47 of 69Code

Code Exercise 5 Debug.Print Study Code Exercise 5 Debug.Print Study QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Output the Condition Attribute?Output the Condition Attribute?

2.2. If you had a fast loop presenting stimuli If you had a fast loop presenting stimuli every 14 ms how might you debug.print to every 14 ms how might you debug.print to see what the stimuli were?see what the stimuli were?

3.3. If you had a 2 monitor computer and you If you had a 2 monitor computer and you ran the experiment on the primary monitor ran the experiment on the primary monitor and the Output window on the second and the Output window on the second monitor, what do you think you would see monitor, what do you think you would see during the run? during the run?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 48: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

48 of 69Code

Code Example 6. Use of code to provide Code Example 6. Use of code to provide cumulative data about the trial number to the cumulative data about the trial number to the

subjectsubject

Code that maintains static variables typically must be declared in the User script, initiated in the beginning of the experiment, and updated during the trial procedure.

Page 49: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

49 of 69Code

Run Trial Counter Run Trial Counter ProgramProgram

1. Open #CodeExercise6-CumulativeData.es 1. Open #CodeExercise6-CumulativeData.es (My Documents\My Experiments\Workshop\(My Documents\My Experiments\Workshop\E-Prime Exercises\).E-Prime Exercises\).

2. Run the experiment, note the 2. Run the experiment, note the TrialCounter on the Probe display.TrialCounter on the Probe display.

Page 50: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

50 of 69Code

Declare a Global VariableDeclare a Global Variable 3. Open the Script 3. Open the Script

window via the View window via the View menu.menu.

4. Declare variable in 4. Declare variable in the User Script window.the User Script window.

BeforeBefore

AfterAfter

Page 51: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

51 of 69Code

Initialize VariableInitialize Variable 5. Initialize the number of 5. Initialize the number of

correct responses in a row by correct responses in a row by setting the variable to 0 as was setting the variable to 0 as was done for the total number of done for the total number of trials. trials.

BeforeBefore

AfterAfter

Page 52: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

52 of 69Code

Add Code to Check Corrects in Row And Set Add Code to Check Corrects in Row And Set CountCount

6. Open the 6. Open the TotalTrialCounterCodeTotalTrialCounterCode

7. Set the Attribute 7. Set the Attribute TotalCurrentRun to the TotalCurrentRun to the g_NTotalCorrectRung_NTotalCorrectRun

8. Add Code that 8. Add Code that if g_nTotalCorrectRun >= 5 Thenif g_nTotalCorrectRun >= 5 Then

Exit SubExit Sub

(This will exit the TrialProc (This will exit the TrialProc whenever the number correct is whenever the number correct is 5 or more). 5 or more).

Page 53: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

53 of 69Code

Add Display Of Corrects In A RowAdd Display Of Corrects In A Row

7. Open 7. Open FixationFixation object. Add object. Add Total Correct in Row [TotalCorrectRun]Total Correct in Row [TotalCorrectRun]

To show number correct in a row.To show number correct in a row.

Page 54: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

54 of 69Code

Calculate Correct RunCalculate Correct Run 8. Add a InLine object after Probe8. Add a InLine object after Probe 9. Rename It CalculateRunCorrects9. Rename It CalculateRunCorrects 10. Enter If statement, increment if 10. Enter If statement, increment if

correct, set to zero if wrong. correct, set to zero if wrong.

Page 55: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

55 of 69Code

Run ProgramRun Program 10. Examine the 10. Examine the

structure.structure.

11. Run to test the 11. Run to test the program.program. Watch the correct run Watch the correct run

conterconter Make 2 correct, then an Make 2 correct, then an

error, then 5 in a correct in a error, then 5 in a correct in a row (the program should row (the program should stop)stop)

12. Save as 12. Save as CodeExample5.es.CodeExample5.es.

Page 56: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

56 of 69Code

Code Exercise 6 Cumulative Data Code Exercise 6 Cumulative Data CollectionCollection

Could you at this point?Could you at this point?

1.1. Add a cumulative trial counter informing Add a cumulative trial counter informing the subject that this is trial [trialcounter] of the subject that this is trial [trialcounter] of the maximum number of trials?the maximum number of trials?

2.2. Have a practice block where the task is Have a practice block where the task is easier and subjects continue till they reach easier and subjects continue till they reach 90% accuracy before moving on?90% accuracy before moving on?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 57: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

57 of 69Code

Exercise 7. Port Input Exercise 7. Port Input OutputOutput

If you need to read a digital input output If you need to read a digital input output bit or write one that can be done by bit or write one that can be done by writing code to operate with a port writing code to operate with a port command then program command then program CodeExercise1PortIO.ex provides an CodeExercise1PortIO.ex provides an example. It reads from a port example. It reads from a port displaying the contents and writes displaying the contents and writes patterns of all bits on and off. patterns of all bits on and off.

This program requires special hardware to This program requires special hardware to respond to the bits. The joystick can be respond to the bits. The joystick can be used for input and printer port devices used for input and printer port devices for input output.for input output.

Page 58: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

58 of 69Code

Specification of Port AddressSpecification of Port Address 1. Load #CodeExercise7PortIO.es1. Load #CodeExercise7PortIO.es

2. Examine the declaration of the 2. Examine the declaration of the Port/IOPort/IO

Page 59: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

59 of 69Code

Reading a Digital PortReading a Digital Port 3. Examine code to read the port3. Examine code to read the port

Page 60: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

60 of 69Code

Writing to a Digital PortWriting to a Digital Port 4. Examine code to write data to a port4. Examine code to write data to a port

5. Run the program if you have a device to show 5. Run the program if you have a device to show the data of the port read. For joy stick change the the data of the port read. For joy stick change the port address code port address code

Page 61: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

61 of 69Code

Code Exercise 7 Port I/O Code Exercise 7 Port I/O QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Turn on the lights differentially reporting Turn on the lights differentially reporting accuracy green on correct and red on accuracy green on correct and red on wrong?wrong?

2.2. Terminate a block when the black box Terminate a block when the black box button is pushed?button is pushed?

3.3. Output a string of bits one every 20 ms.Output a string of bits one every 20 ms.

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 62: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

62 of 69Code

Exercise 8 Optional - Exercise 8 Optional - OnsetSignalOnsetSignal

Add OnsetSignalCondition code to Add OnsetSignalCondition code to signal the condition on the parallel Port signal the condition on the parallel Port to #BasicExercise1Lex.es to #BasicExercise1Lex.es oror load load #CodeExercise8OnsetSignal.ebs#CodeExercise8OnsetSignal.ebs

Note code in Note code in violet violet rectangle code is usually in initialization sectionrectangle code is usually in initialization section

Page 63: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

63 of 69Code

Code Exercise 8 Onset SynchCode Exercise 8 Onset Synch

Could you at this point?Could you at this point?

1.1. Set the onset synch to report when the Set the onset synch to report when the fixation occurred with a 1 code, when the fixation occurred with a 1 code, when the stimulus occurred with a 2 code?stimulus occurred with a 2 code?

2.2. Change the data signal to reflect what Change the data signal to reflect what stimulus was presented?stimulus was presented?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 64: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

64 of 69Code

Exercise 9 Optional - LoopExercise 9 Optional - Loop 1. Load and run #CodeExercise9Loop.es1. Load and run #CodeExercise9Loop.es 2. Change the Probe.x and Probe.y position 2. Change the Probe.x and Probe.y position

after after ForFor command and rerun. command and rerun. Probe.x = 4 * counter + 10Probe.x = 4 * counter + 10 Probe.y = 4 * counter + 10Probe.y = 4 * counter + 10

Page 65: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

65 of 69Code

Code Exercise 9 Frame Loop Code Exercise 9 Frame Loop QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Add a fixation stimulus to the loop in Add a fixation stimulus to the loop in #CodeExercise9Loop?#CodeExercise9Loop?

2.2. Add code to exit the loop when the subject Add code to exit the loop when the subject makes a correct response?makes a correct response?

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix

Page 66: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

66 of 69Code

Exercise 10 (Optional) Exercise 10 (Optional) ReSamplingReSampling

This exercise uses code to resample a list to sample This exercise uses code to resample a list to sample a list and reject any repeat conditions in the list. a list and reject any repeat conditions in the list. It uses a subroutine to do the sampling. To use a It uses a subroutine to do the sampling. To use a user defined subroutine it must be in the User user defined subroutine it must be in the User section.section.

This will manually force a sampling from the This will manually force a sampling from the ConditionList putting all of those conditions in the ConditionList putting all of those conditions in the context. If this is put in a loop (e g., While) this context. If this is put in a loop (e g., While) this can sample skipping unwanted runs of the same can sample skipping unwanted runs of the same condition. condition.

Page 67: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

67 of 69Code

Check Out ProgramCheck Out Program

1. 1. Load and run #CodeExercise10-Load and run #CodeExercise10-Resample.esResample.es

2. Examine the code. Note use of 2. Examine the code. Note use of LastCondition to verify no repeats.LastCondition to verify no repeats.

3. Run the program note no runs3. Run the program note no runs

Page 68: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

68 of 69Code

Examine ManualSample Examine ManualSample SubroutineSubroutine

4. Examine the User code with the subroutine for sampling. 4. Examine the User code with the subroutine for sampling. Note this subroutine uses sophisticated techniques to pass in Note this subroutine uses sophisticated techniques to pass in the list name. For now, just note that this code must be placed the list name. For now, just note that this code must be placed in the User code section so you can refer to the in the User code section so you can refer to the ManuallySampleList function. ManuallySampleList function.

Page 69: 1 of 69 Code Script Exercises (1- 10) Code for Experiments E-Prime 2002 Workshop Files on My Documents\My Experiments\Workshop\E-Prime Exercises E-Prime.

69 of 69Code

Code Exercise 10 ReSampling Code Exercise 10 ReSampling QuestionsQuestions

Could you at this point?Could you at this point?

1.1. Modify #CodeExercise10-Resample to have Modify #CodeExercise10-Resample to have four conditions and make sure there are no four conditions and make sure there are no repetitions?repetitions?

2.2. Copy the subroutine from Copy the subroutine from #CodeExercise10-Resample to another #CodeExercise10-Resample to another program so you could use the program so you could use the ManuallySampleList in another program. ManuallySampleList in another program.

Short Answers are included in the Exercise AppendixShort Answers are included in the Exercise Appendix