EPrime Script Exercises - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

EPrime Script Exercises

Description:

... multiple executions in the User Code area (display the Script window via the ... 19. Search for the cresp correct response designation. 20. Open up the ... – PowerPoint PPT presentation

Number of Views:675
Avg rating:3.0/5.0
Slides: 70
Provided by: Carolin7
Category:

less

Transcript and Presenter's Notes

Title: EPrime Script Exercises


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.x0), or execute
objects (e.g., TextDisplay.run). Query
properties of other objects as needed (e.g.,
localvariableBitmap.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
    DisplayGraphics

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 statement for a repetitive action and
    an IF statement for conditional actions.

If x gt 10
For counter Start to End
Action True
Action False
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 gt 10
Action True
If x gt 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
  • 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

Note the comments explain the mod function to get
a remainder and the CColor to set the color
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 WhileWhen, DoLoop 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
51
Initialize Variable
  • 5. Initialize the number of correct responses in
    a row by setting the variable to 0 as was done
    for the total number of trials.

Before
After
52
Add Code to Check Corrects in Row And Set Count
  • 6. Open the TotalTrialCounterCode
  • 7. Set the Attribute TotalCurrentRun to the
    g_NTotalCorrectRun
  • 8. Add Code that
  • if g_nTotalCorrectRun gt 5 Then
  • Exit Sub
  • (This will exit the TrialProc whenever the number
    correct is 5 or more).

53
Add Display Of Corrects In A Row
  • 7. Open Fixation object. Add
  • Total Correct in Row TotalCorrectRun
  • To show number correct in a row.

54
Calculate Correct Run
  • 8. Add a InLine object after Probe
  • 9. Rename It CalculateRunCorrects
  • 10. Enter If statement, increment if correct,
    set to zero if wrong.

55
Run Program
  • 10. Examine the structure.
  • 11. Run to test the program.
  • Watch the correct run conter
  • Make 2 correct, then an error, then 5 in a
    correct in a row (the program should stop)
  • 12. Save as CodeExample5.es.

56
Code Exercise 6 Cumulative Data Collection
  • Could you at this point?
  • Add a cumulative trial counter informing the
    subject that this is trial trialcounter of the
    maximum number of trials?
  • Have a practice block where the task is easier
    and subjects continue till they reach 90
    accuracy before moving on?

Short Answers are included in the Exercise
Appendix
57
Exercise 7. Port Input Output
  • If you need to read a digital input output bit or
    write one that can be done by writing code to
    operate with a port command then program
    CodeExercise1PortIO.ex provides an example. It
    reads from a port displaying the contents and
    writes patterns of all bits on and off.
  • This program requires special hardware to respond
    to the bits. The joystick can be used for input
    and printer port devices for input output.

58
Specification of Port Address
  • 1. Load CodeExercise7PortIO.es
  • 2. Examine the declaration of the Port/IO

59
Reading a Digital Port
  • 3. Examine code to read the port

60
Writing to a Digital Port
  • 4. Examine code to write data to a port
  • 5. Run the program if you have a device to show
    the data of the port read. For joy stick change
    the port address code

61
Code Exercise 7 Port I/O Questions
  • Could you at this point?
  • Turn on the lights differentially reporting
    accuracy green on correct and red on wrong?
  • Terminate a block when the black box button is
    pushed?
  • Output a string of bits one every 20 ms.

Short Answers are included in the Exercise
Appendix
62
Exercise 8 Optional - OnsetSignal
  • Add OnsetSignalCondition code to signal the
    condition on the parallel Port to
    BasicExercise1Lex.es or load CodeExercise8OnsetS
    ignal.ebs

Note code in violet rectangle code is usually in
initialization section
63
Code Exercise 8 Onset Synch
  • Could you at this point?
  • Set the onset synch to report when the fixation
    occurred with a 1 code, when the stimulus
    occurred with a 2 code?
  • Change the data signal to reflect what stimulus
    was presented?

Short Answers are included in the Exercise
Appendix
64
Exercise 9 Optional - Loop
  • 1. Load and run CodeExercise9Loop.es
  • 2. Change the Probe.x and Probe.y position after
    For command and rerun.
  • Probe.x 4 counter 10
  • Probe.y 4 counter 10

65
Code Exercise 9 Frame Loop Questions
  • Could you at this point?
  • Add a fixation stimulus to the loop in
    CodeExercise9Loop?
  • Add code to exit the loop when the subject makes
    a correct response?

Short Answers are included in the Exercise
Appendix
66
Exercise 10 (Optional) ReSampling
  • This exercise uses code to resample a list to
    sample a list and reject any repeat conditions in
    the list. It uses a subroutine to do the
    sampling. To use a user defined subroutine it
    must be in the User section.
  • This will manually force a sampling from the
    ConditionList putting all of those conditions in
    the context. If this is put in a loop (e g.,
    While) this can sample skipping unwanted runs of
    the same condition.

67
Check Out Program
  • 1. Load and run CodeExercise10-Resample.es
  • 2. Examine the code. Note use of LastCondition
    to verify no repeats.
  • 3. Run the program note no runs

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

69
Code Exercise 10 ReSampling Questions
  • Could you at this point?
  • Modify CodeExercise10-Resample to have four
    conditions and make sure there are no
    repetitions?
  • Copy the subroutine from CodeExercise10-Resample
    to another program so you could use the
    ManuallySampleList in another program.

Short Answers are included in the Exercise
Appendix
Write a Comment
User Comments (0)
About PowerShow.com