Slide duration defined by variable, not attribute

682 views
Skip to first unread message

Tobias

unread,
Jul 7, 2011, 1:23:45 PM7/7/11
to E-Prime
Hi,

I would like to define the duration of an object (slide in this case)
in E-Prime with a variable. As far as I know, instead of specifying
the duration directly by a number, you can also use square brackets
and enter, let's say [durationA]. This refers to the attribute in the
current list named "durationA". However, using attributes is much more
complicated and not really straight forward. Is there a way of using
variables instead?

Thanks a lot in advance!
Tobias

David McFarlane

unread,
Jul 7, 2011, 1:56:09 PM7/7/11
to e-p...@googlegroups.com
Tobias,

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

Tobias

unread,
Jul 8, 2011, 7:23:24 AM7/8/11
to E-Prime
Thanks for your sage advice. I think I just found it annoying to
always use "c.setattrib" etc., never really knowing by heart the exact
syntax. Also, I sometimes had error mesagges because the variable
types didn't match etc. I'll think about it, but for the moment: THis
snip of code you were writing, at what point in the procedure should I
include it? I was actually aware that "StimText.Duration = durationA"
should work, but if I put at a point before the object, the value
entered in the object will overwrite it. And after the object, it's
already too late :-p

Best,
Tobias

David McFarlane

unread,
Jul 8, 2011, 10:03:52 AM7/8/11
to e-p...@googlegroups.com
Tobias,

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

Tobias

unread,
Jul 11, 2011, 6:03:26 AM7/11/11
to E-Prime
The problem was that I was still referring to an attribute...

so thanks for the hint!

best,
Tobias
Reply all
Reply to author
Forward
0 new messages