First, I disagree with your premise about attribute references being
"more complicated and not really straight forward" than
variables. It is just as simple and straightforward to use attribute
references in code as it is to use variables in code, and in most
cases attribute references offer distince advantages. I started out
using variables just as you describe (and so will get around to
actually answering your question :)), but once I understood attribute
references better I switched to using those whenever I can, for the
following reasons:
- Using a variable for, say, Duration, leaves *no* clue in the
program design that that value will vary -- to the contrary, the
object's Duration will show as a constant, so programmers just have
to "know" that this value will vary in some code somewhere. By
contrast, an attribute reference in the object serves notice that
that value varies, and thus is much "friendlier" to programmers.
- Using a variable does *not* log the varying value, so after the
experiment you have no record of what really happened. Using an
attribute reference fixes this at no extra cost. Yes, you could
throw in a c.SetAttrib "DurationA", durationA just to log the, but
once you go to that length you might as well just use the attribute
in your object, no?
So except for extreme cases, if I need to vary a property value from
code instead of a List, I always do something like
c.SetAttrib "DurationA", durationA
and then use [DurationA] for the Duration property of my stimulus object.
But let's suppose that you really have a valid purpose for this (or
wish to simply ignore my sage advice). Here's how you do
that. Suppose you want to set the Duration property of a stimlus
object called StimText to a variable called durationA. In code, you simply do
StimText.Duration = durationA
That's it! Absurdly simple. You can do this for a whole host of
object properties, just look at the E-Basic Help page for any desired
object. For that matter, work through Chapter 4 of the User's Guide
that came with E-Prime, and take a course in Introduction to Computer
Programming.
Regards,
-- David McFarlane, Professional Faultfinder
Hmm, well, from this distance I cannot tell what you are doing wrong,
I just put the code anywhere before the object and it works perfectly
for me (I tried just now and made absolutely sure). (I did have to
make sure to type in the correct number -- I first mistakenly typed
"5" for 5 s, forgetting that I had to enter 5000 for 5000 ms, once I
did that it was OK. So do make sure you have entered the correct
values.) More importantly, on the object itself I just left the
Duration at its default of 1000. The exact value does not matter at
all, but you must, *must* use a literal value in the Duration
property of the object itself, do *not* use an attribute
reference!! If you use an attribute reference for the duration then
that attribute value will replace the value from your earlier code --
you could see this for yourself simply by looking at the source code
that E-Studio generates, you don't need my help to figure this out.
Of course, putting a literal value in for the Duration of the object
will deceive users into thinking that the Duration for that object is
that literal value, instead of the value that comes from your inline
code, which is the point of my first objection below. And if you can
get this to work by setting an attribute reference in code, then why
bother getting it to work withouth the attribute reference, except as
a mere academic exercise (of which I would approve)?
-- David McFarlane, Professional Faultfinder