1 / 69

E-Prime Script Exercises

E-Prime Script Exercises. Script Exercises (1- 10) Code for Experiments. E-Prime 2002 Workshop Files on My DocumentsMy ExperimentsWorkshopE-Prime Exercises. E-Prime Code Tutorials. Use of help facility. Use of Code to Set a Property. Program flow control.

vilhelm
Download Presentation

E-Prime Script Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. E-Prime Code Tutorials • Use of help facility. • Use of Code to Set a Property. • Program flow control. • Use of Code to Set the Stimulus Conditional on a List Attribute. • Using Debug.Print to Report Event Times and debugging. • Use of code to provide cumulative data and exit block when five correct answers in a row. (Optional). • Using code to read a digital IO bit and set digital bit (optional). • Use of Onset Synch to control external hardware (optional). • Use of loop to present frames (optional). • Sample data from a list and delete repeats (optional).

  3. Basic Steps to Writing Code 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.

  4. Exercise 1: Using E-Basic Online Help The are over 1000 pages of online help for E-Basic. Use the help to find commands, learn their syntax, and get examples on how to use the commands. This short example will show how to find a command (Display.Rectangle) copy an example and run it and how to find things in the E-Basic Help.

  5. Opening E-Basic Help • 1. Open a new Experiment in E-Studio • 2. Create an InLine object for later use in example to copy code to. Click and drag the Inline Object to the SessionProc • 3. Open Help, Click the Help Menu select E-Basic Help. • 4. Scroll through the list of commands, go to the Display:Graphics

  6. Select Command, Examine Help • 5. Click on “Canvas.Rectangle (method)” • 6. Examine the help. Check the Syntax, Description, Comments, Example, and See Also

  7. Copy Example From Help • 7. Copy the example into the copy buffer • Move cursor to beginning of ‘This sample.. Move cursor to end example • Click and drag to the end of the example (it will reverse highlight the text) • Copy the example with Ctrl-C or Right click/copy

  8. Paste Example Into Experiment • 8. Open the Inline object, paste (type Ctrl-V) the text into the inline object • 9. Check that all lines copied completely, (note first and last lines should be green comment lines) • 10. Run the example it should put up a green square Display

  9. Modify Parameters • 11. To learn parameters it is good to change some of the parameters to see if they do what is expected. Change: • width w= 600 • pen color to red • pen width to 40 • 12. Rerun experiment Display The example is in the exercises with the file name #CodeExercise1-Help.es

  10. E-Basic Help - Table of Contents The Contents allows you to browse the help. It is particularly helpful for identifying summaries of commands and families of commands. • 13. Open E-Basic help • 14. Select Help Topics • 15. Click Contents tab, look at contents for alphabetic list of commands • Note if you double click on E-Basic and click Welcome you get the command summary • Double click on other topics to expand the listings and browse the table of contents of the commands.

  11. E-Basic Help - Index The Index allows you to find specific commands when you know the name of the command or function. • 16. Use the Index to get the specific topic, Click Index, type Special Keys double click topic or press display • 17. Look at special keys listing of how to enter keys such as the {ANY}. Scroll through to view List of special keys

  12. E-Basic Help - Find 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 Find will locate the help pages that include that string. • 18. Select the Find Help option. • 19. Search for the cresp – correct response designation. • 20. Open up the specification.

  13. Help Exercise Summary • Use the online help. • When needing a given type of command use the Contents under the Topic E-Basic Welcome. • Use the Index for finding commands of interest when you know the name. • Use the Find if the topic is not in the index but you know a related term. • For new commands it is a good practice to copy the example and run it stand alone before trying to use it in new functions.

  14. Code Exercise 1 Study Questions Could you at this point? • Use the Help to find how to declare an integer type variable? • Find the syntax and an example of the IF command? • Find a command that examines a command which would allow you to pick a member of a text string “red,green,blue,black” with an index to pick the correct word? • Determine how to exit a subroutine early? Short Answers are included in the Exercise Appendix

  15. Code 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.

  16. Use of Code to Set a Property • 1. Open #CodeExercise2-SetProperty.es (My Documents\My Experiments\Workshop\E-Prime Exercises\) • 2. Run the experiment, notice the random placement of the stimuli on the screen

  17. Edit StimPosition Code • 3. Open the StimPosition Inline object and edit the program to randomly present stimuli along the y-axis Before After

  18. Run And Test Program • 4. Run and test the program • 5. Save as CodeExample2.es

  19. Looking Up Properties Of An Object • 6. Examine the properties window of the Probe object in E-Studio. This illustrates most of the properties and how they are set • If not open open the properties window • Scroll through the properties • Determine default value of the font size

  20. Getting Help On Object Properties • 7. You can get documentation on the properties either in the E-Prime Reference manual or the Help topics • Open the Help topics • Select Text Display Object Properties Window

  21. Examine Properties Set FontSize • 8. Examine the properties specification • 9. Add a command Set the font size to vary in units of 20 points randomly from 20 to 100 points

  22. Use Item Function to Choose Option • 10. Setting a property with the Item function. Often there is a need to choose items from a set of items. This is illustrated by selecting the FontName • Use Item$ function to choose the font from a list of items • Add a command to randomly choose the FontName • 11. Run the program examine font size and type

  23. Setting Yes/No Explicit List Properties 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. 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. • 11. Set the FontItalic function off/on by selecting 0/1 • 12. Select the color from a list, chose color function ccolor. The function coverts a string containing a color name to 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 program.

  24. Setting 8 Properties of a Text Display • 13. Examine this example. It sets 8 parameters representing 57600 (4x4x5x2x2x3x6x10) possible possible variations of the stimulus in 8 lines of code. (Note this is example #CodeExercise2-SetPropertyMulitpleParameters.es)

  25. Code Exercise 2 Properties Study Questions Could you at this point set properties of objects? • Change the font to bold? • Change background colors of the display? • Set the X position of the Fixation display to be the same as the Probe? Short Answers are included in the Exercise Appendix

  26. Exercise 3 Execution Control Execution flow control allows repetitive actions or conditional actions. In this example we will use a For statementfor a repetitive action and an IF statement for conditional actions. If x > 10 For counter = Start to End Action False Action True Loop Action

  27. Exercise 3 Execution Control For counter = Start to End Examine the code note the: • For next loop • IF conditions The indenting shows the commands in the for loop. If x > 10 Action True If x > 10 Action True Loop Action

  28. Load and Execute • 1. Open #CodeExercise3-ProgramControl.es from My Documents\My Experiments\Workshop\E-Prime Exercises\. • 2. Examine the InLine1 code. Note it is #CodeExercise1-Help.es with a For and If statements. • 3. Run the program see the moving box

  29. Add an IF Then Note the comments explain the mod function to get a remainder and the CColor to set the color • 4. Add the IF Else statements shown • If begins the conditional execution • Then is the true action • Else the False Action • End IF finishes the If

  30. Run Program With If Then • 5. Run the program. Observe the color change. • 6. Change the maximum of the For and add ElseIf instead of Else for 3 states.

  31. Run Program • 7. Run program examine results. • 8 Save program as CodeExercise3.ex

  32. Code Exercise 3 Program Control Questions Could you at this point? • Add a loop to present the square in #CodeExercise3-ProgramControl to make the square move up for 1000 iterations, down and be a circle for 1000 iterations, and move horizontally and be an oval. • Find other program control commands and implement a While…When, Do…Loop or Case process. • Specify how to leave a For loop early (not covered in exercise but in lecture). Short Answers are included in the Exercise Appendix

  33. Code Exercise 4. Use of Code to Set the Stimulus Conditional 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.

  34. Open Code Examine Get Attribute • 1. Open #CodeExercise4-ListAttribute.es from My Documents\My Experiments\Workshop\E-Prime Exercises\. 2. Examine the code and list and predict what will occur.

  35. Run And Check for Error • 3. Run the experiment • Note you will see a message box appear on the last trial to indicate that a coding error has occurred, hit enter. This is intentional to illustrate self checking code. • In this case the Bad Condition = bxlow indicates that a spelling error has been detected in the Condition.

  36. Correct Errors • 5. Open List1 and edit bxlow to below. After Before

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

  38. Edit Instructions • 7. Edit display instructions located on the Fixation display. Before After

  39. Run and Test Program • 8. Save as CodeExample4.es. • 9. Run to test the program, note the random numbers selected are now between 1-9.

  40. Code Exercise 4 Attributes Questions Could you at this point? • Use Code to set the attribute of font color based on the Condition? • Explain the difference in using code to set an attribute and setting an attribute and setting the property of the attribute using the [attribute] syntax? • Predict what would happen if an attribute is set multiple times in the same procedure? Short Answers are included in the Exercise Appendix

  41. Exercise 5: Using Debug.Print to Report Event Times 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.

  42. Run Debug.Print Exercise • 1. Open #CodeExercise5-DebugPrint.es (My Documents\My Experiments\Workshop\E-Prime Exercises\). • 2. Run the experiment, note the use of the RandomNumberGenerate code.

  43. View Output Window • 3. View Output window located at the bottom of the screen. Click on View menu and select Output.

  44. Copy and Clear Debug Output • 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 click (otherwise the output is appended). Copy the output and paste it into Excel. This is useful for using Excel to check timing issues such as the time between stimuli. • Select all the output with click start and drag to end • Copy • Clear the information • 5. Open Excel • Select first cell • Paste the copied items • Calculate onset time to onset time Onset time enter in Cell F1 = A2-A1

  45. Edit Debug.Print • 6. Examine and edit DebugPrint note: • The “\t” puts a tab in the string (which causes tab to new column in Excel spreadsheet in copy • The & concatenates strings • The _ at the end of a line continues a line • 7. Add an output of a Probe.RT to report the response time in the output window. Before After

  46. View Output Window • 5. Run program and view Output window, note that the Prob.OnsetTime is now included in the Output window. • 6. Save as CodeExample4.es. Before After

  47. Code Exercise 5 Debug.Print Study Questions Could you at this point? • Output the Condition Attribute? • If you had a fast loop presenting stimuli every 14 ms how might you debug.print to see what the stimuli were? • If you had a 2 monitor computer and you ran the experiment on the primary monitor and the Output window on the second monitor, what do you think you would see during the run? Short Answers are included in the Exercise Appendix

  48. Code Example 6. Use of code to provide cumulative data about the trial number to the subject 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.

  49. Run Trial Counter Program • 1. Open #CodeExercise6-CumulativeData.es (My Documents\My Experiments\Workshop\E-Prime Exercises\). • 2. Run the experiment, note the TrialCounter on the Probe display.

  50. Declare a Global Variable • 3. Open the Script window via the View menu. • 4. Declare variable in the User Script window. Before After

More Related