Mastering E-Prime: How to Learn E-Prime Programming

5,313 views
Skip to first unread message

David McFarlane

unread,
May 10, 2011, 4:02:40 PM5/10/11
to e-p...@googlegroups.com
The question comes up from time to time, "How can
I learn to program with E-Prime?" Here is my attempt to answer that.

First, some earlier posted partial attempts to address this:
http://support.pstnet.com/forum/Topic1806-5-1.aspx
http://support.pstnet.com/forum/Topic2316-5-1.aspx
http://support.pstnet.com/forum/Topic2951-12-1.aspx
http://support.pstnet.com/forum/Topic2446-23-1.aspx
http://groups.google.com/group/e-prime/browse_thread/thread/e4b89ad5265c747a/b1ec5d104cc7977d
( http://listserv.linguistlist.org/cgi-bin/wa?A2=ind0804D&L=EPRIME&P=R1715 )

And now, my essay...

For those without any programming background:
- E-Prime is well suited for casual, amateur programmers of simple
psychological experiments, insofar as it insulates the user from the
deeper workings of the system (and encapsulates several structures and
concepts peculiar to experimental psychology). As a result, it makes
a poor platform for learning or understanding actual computer
programming. If you try this you will only make things hard on
yourself.
- I urge you instead to just knuckle down and do some actual coursework
in any modern object-oriented programming language until you at least
grasp some general core concepts (bits, bytes, words, literals,
constants, variables, integers, floats, strings, arrays, objects,
representations, types, classes, scope, operators, labels,
conditionals, branches, loops, blocks, subroutines, functions,
arguments, etc.). Otherwise you will not understand what we are
talking about.
- Since E-Basic is a derived from Microsoft Visual Basic for
Applicatons (the language element of Visual Basic 6), you would do
best to study this if possible.
- Some of us who hearken back to the 1980s still think that Pascal
makes a fine language for learning general programming concepts,
but it has fallen out of fashion. (And if you did study Pascal,
you would want an object-oriented version, e.g., ObjectPascal.)
- You can use any web browser (e.g., Internet Explorer, Firefox,
Opera) to study JavaScript, which incorporates a rich set of
object-oriented concepts, for free. However, JavaScript quickly
gets entangled with HTML, Cascading Style Sheets, and the Document
Object Model, so this may not be so useful as I once thought.
- Python is also free, and seems to be generally in fashion now for
Introduction to Programming, so you might try that.
- Python does not let you learn directly about labels and goto
statements, which you will need for E-Prime. But you might
learn similar concepts with Python's exception handling
(i.e., try, raise, except).
- Personally, for this kind of work I think you cannot do better
than to get a good grounding in C or C++, but I seem to be
outvoted here.
- Even more fundamental than learning any programming language, you
should study and be comfortable with math in general, and in
particular propositional logic, combinatorics, and probability.
- It also helps to know some information and communication theory.
(If you can make it through the classic work of Claude Shannon,
then you are in good shape.)
- See my "How to Solve E-Prime Puzzles".

For those who come to E-Prime with some programming background:
- E-Basic is a derived from Microsoft Visual Basic for Applications
(the language element of Visual Basic 6). So you might like some
materials on VB or VBA.
- Most materials on Visual Basic focus on using the VB GUI to design
the GUI aspects of your program, and using VB to control
databases and web sites, so they are not much use to us.
Instead, you want a source that covers the basic language
elements.
- Books to try:
- "VBA for Dummies", Steve Cummings, IDG Books Worldwide, Inc.,
Foster City, CA, 1998.
- "VB and VBA in a Nutshell: The Language", Paul Lomax,
O'Reilly Media, Inc., Sebastopol, CA, 1998.
- "VBA Developer's Handbook", Ken Getz & Mike Gilbert, Sybex
Inc., San Francisco, CA, 1997.
- "VBA for Dummies" and "VBA Developer's Handbook" come
recommended in the E-Prime User's Guide (p. 124, sec. 4.1.1).
- I find "VBA for Dummies" to make the best general discursive
introduction (despite its annoyingly chatty style). "VB and
VBA in a Nutshell", true to O'Reilly's general quality, makes
a generally good reference book. "VBA Developer's Handbook"
is really meant for a different audience (developers of
commercial VBA applications).
- E-Basic lacks some standard VBA elements (e.g., With).
- E-Basic extends VBA with its own host of classes/objects (and
associated properties and methods), so VB books only help so far.
- In addition, vital task control issues such as randomization and
critical timing go beyond the scope of most programming texts, so
you will have to learn those separately (e.g., Chapter 3 of the
E-Prime User's Guide).
- BTW, the E-Studio environment itself borrows a lot from the
Visual Basic Editor.
- Some features of E-Prime (e.g., graphics and timing) rely on
Microsoft's DirectX technology, so you may wish to also study that.
- The Guides supplied with E-Prime do a pretty good job as far as they
go, but they are rather tutorial in nature and scope. There is
neither a proper technical reference, nor any discursive guide to lay
out the underlying principles and concepts of E-Prime and E-Basic.
You are left to puzzle this out for yourself, or along with other
regular users.
- Make lots of small demo programs in E-Studio, and study the
generated code.
- Use Lists and Weights to easily limit test runs.
- Use Clock.Scale for speeded test runs.
- Log test values (c.SetAttrib) and examine the resulting
.edat* file *after* test runs to see what the program did.
- Or, use Debug.Print (per Michiel Spapé).
- Or, use MsgBox to trace execution at run time.
- Use GetUserBreakState() for graceful early exits.
- If you have EP1, use E-Run to try out E-Basic elements with even
simpler test programs. You can do this even without a hardware
key (which is probably why PST removed this capability from E-Run
in EP2). In this regard, EP2 makes an inferior platform for
studying E-Basic.
- See my "How to Solve E-Prime Puzzles".
- In particular, study Chapter 4, "Using E-Basic", of the User's
Guide.
- If you care at all about critical timing, then someone in
your lab *must* study Chapter 3 of the User's Guide. I
cannot stress this enough.
- The "real" documentation, insofar as we get any at all, is in
the E-Basic Help facility.
- The E-Basic Help facility is still incomplete (e.g.,
http://support.pstnet.com/forum/Topic1241-12-1.aspx ), and
in some cases misleading or just plain wrong (e.g.,
http://support.pstnet.com/forum/Topic1197-5-1.aspx ).

-- David McFarlane, Professional Faultfinder

ben robinson

unread,
May 11, 2011, 11:07:28 AM5/11/11
to e-p...@googlegroups.com
Clock.Scale?  amazing.  thank you, david!


--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.


David McFarlane

unread,
May 12, 2011, 12:21:46 PM5/12/11
to e-p...@googlegroups.com
Ben,

At 5/11/2011 11:07 AM Wednesday, ben robinson wrote:
>Clock.Scale? amazing. thank you, david!

Since you mention it, I will expand that detail a little more. As
you found, Clock.Scale allows you to speed up (or slow down) the
clock rate in E-Prime. It is meant primarily for synchronizing the
clock to other equipment, but I find it very handy for speeding up test runs.

I am going to give you a bit of enhanced inline code for safely using
Clock.Scale for this purpose, but first I need to motivate this with
a story. When I discovered Clock.Scale many years ago, first I would
simply put it in an inline in my program for my test runs. Of
course, then I had to remember to remove or disable my Clock.Scale
before using the program with subjects, imagine the trouble if I
forgot! At first I would try to remember to delete the line before
running subjects, but then I would have to type it back in for new
test runs. Then I tried merely commenting it out as needed, which
left the line in place but still ran the risk of me forgetting to
comment it out as needed. Then I tried putting it into its own
inline, and "deleting" that to Unreferenced E-Objects as needed, and
dragging it back into SessionProc for test runs. Again, that ran the
risk of forgetting to disable my Clock.Scale for subject runs.

I thought I could get more clever, so I decided to use a "secret
handshake" to start test runs, which would then present a warning
reminder before setting the Clock.Scale. I wanted to use a negative
Session number, but E-Prime didn't like that so I settled on 11111
(that's five ones). Then I thought, in addition to a warning, it
should give the user a chance to bail out. Then I thought, as long
as it does all that, why not have it ask me for the Clock.Scale
value, so I can change it from run to run? And log the Clock.Scale
value? And give me a chance to enter arbitrary comments to
log? Etc. Now I can just leave that code in place and invoke it
only for test runs, during subject runs it has no effect.

So this keeps evolving, but here is the current bit of code that I
put into its own inline at the start of almost every project (I like
to name the inline "DeveloperInitCode"):


'/----------------------------------------------------------------------
' Inline code to enable various development aids.

Const DebugTrigger = 11111
Const ClockScaleAskDefault as Single = 0.05
Dim x

If c.GetAttrib("Session") = DebugTrigger Then
Beep
x = AnswerBox( "You entered a session number of " & DebugTrigger _
& ".\nThis enables some extra developer testing script added" _
& " by the developer of this experiment." _
& "\nIf this is not what you meant, use Cancel to quit the" _
& " experiment now.", "OK", "Cancel", , "DeveloperInit Notice" )
If (x <> 1) Then Exit Sub
' Use Clock.Scale to speed up, or slow down, the experiment running
' time for development testing:
x = AskBox( "Clock.Scale (use 1 to run with normal timing): ", _
ClockScaleAskDefault )
If IsEmpty(x) Then Exit Sub
Clock.Scale = x
c.SetAttrib "Clock.Scale", Clock.Scale
c.SetAttrib "Comment", AskBox( "Comment:" )
End If
'\----------------------------------------------------------------------


Sometimes I crank the Clock.Scale all the way down (up?) to 0.01,
speeding the run up by a factor of 100. This works great for
programs that do not wait for subject responses (such as fMRI) --
e.g., I can run through a 15 min experiment in 9 s and then look at
the .edat file to see what stimuli got presented when, etc.

Now, if only I had an easy programmable way to disable and re-enable
self-paced responses for test runs!

Paul Groot

unread,
May 12, 2011, 4:38:33 PM5/12/11
to e-p...@googlegroups.com
Hi All,

The hidden clock.scale configuration at startup David described is
indeed invaluable for serious programming and testing. A poor man’s
trigger implementation I often use is the following:

If GetUserBreakState<>0
SetUserBreakState 0
Clock.Scale = …
End if

I normally place this after the startup/intro screen. Just pressing
Ctrl+Shift during the intro will enter turbo/slowmotion mode. This
could be useful when the session number is used for something else
(e.g. list ordering: counterbalance, offset, …)

happy programming...

Paul Groot

Reply all
Reply to author
Forward
0 new messages