how to... make a 'for 0 to x' variable that can insert digits IN an attribute name?

159 views
Skip to first unread message

liwenna

unread,
Nov 4, 2009, 3:52:32 PM11/4/09
to E-Prime
Short question:
In the piece of code below: how do I implement a variable that
replaces the digits 1-3 in the attribute names 'restid1' - 'restid3'
so that I can shorter the code to a single line (using an additional
'for 0 to 2' variable for the (randompos(x)) part) ?

**************************************
for m = 1 to 4

triallist.SetAttrib m, "restid1", randomlist(randompos(0))
triallist.SetAttrib m, "restid2", randomlist(randompos(1))
triallist.SetAttrib m, "restid3", randomlist(randompos(2))

randomizearray randompos

next m
***************************************

Long explanation:
Ok.... So... I have this habit of writing enormous inlines because I
am generally to lazy or not in the mood to figure out/learn how to
shorten them.... I decided that I am gonna break this habit and have
choosen a nice litle experiment to do this with. However: I am stuck
now. My hope is that someone here knows off hand what lines I need and
is able to drop me a line.

In the final experiment each display holds 16 positions which will be
filled with one targetstimulus and 15 distractorstimuli. There are 16
possible targetstimuli which will each have to appear in one of the 16
possible positions (a 4x4 grid, 16 locations x16 targetstimuli = 256
trials). The identity of the targetstimulus decides which 15 stimuli
should be used as distractorstimuli and I like to have the location of
each of the distractorstimuli randomized... Unfortunately this means
that for each trial there are 15! possible arrangements of the
distractorstimuli (1 307 674 368 000). I don't like
pseudorandomizations that well so I took up the challenge and actually
got quite far so far. For obvious reasons I am working the whole thing
out with a smaller number of positions: 4 (2x2 grid).

This is what I got now: for target ID 1 a list with the 15
distractorstimuli for this target is loaded from a textfile into an
array and randomized. A second array holds the numbers 1-15 which
corresponds with locations 1-15. For each level of the triallist (m)
the randomized distractorstimuli are randomly loaded into attributes
called "restid1" up to "restid3" (4 locations, 1 holds the target).
When a level is filled, the randompos array is rerandomized so that
for the next level each distractorstimulus is loaded into a different
restid-attribute. The piece of code shown below deals with the first 4
levels (target ID 1), the code will have to repeat for the next 4
levels but then load id2restids.txt instead (containing
distractorstimuli for target ID 2), etc etc. As you can see this
inline will still become rather bulky so here's the question again:
can I shorten the 3 lines that fill the triallist-levels to 1 line by
using another 'for 1 to 3' attribute (one of those mysterious %_ & #
perhaps?) that can actually be used IN an attribute name?

***********************************************
for m = 1 to 4

Open "id1restids.txt" For Input As #1
For n = 0 To 2
Input #1, randomlist(n)
Next n
Close #1

randomizearray randomlist

for q = 0 to 2
randompos(q) = q
next q

randomizearray randompos

triallist.SetAttrib m, "restid1", randomlist(randompos(0))
triallist.SetAttrib m, "restid2", randomlist(randompos(1))
triallist.SetAttrib m, "restid3", randomlist(randompos(2))

randomizearray randompos

next m
*******************************************


I've checked the guides, checked the e-primer, searching all over the
place for a piece of code that I could steal the trick from, but to no
avail so far. What certainly doesn't help is that I so far never quite
got the deal with the & % _ crf things.... (that's probably
embarrassing but true :p )

I hope someone knows a nice solution for me.

Best regards,

liw

ben robinson

unread,
Nov 4, 2009, 4:10:12 PM11/4/09
to e-p...@googlegroups.com
something like this?

for m = 1 to 4

triallist.SetAttrib m, "restid" & m, randomlist(randompos(m-1))

next m

liwenna

unread,
Nov 4, 2009, 4:41:48 PM11/4/09
to E-Prime
Hello Ben,

Thanks for such a quick reply!

It should become something like that indeed!

But... correct me if I am wrong (I am at home now so no e-prime at my
disposal, i'll certainly give it a try tomorrow), it seems that in the
code you wrote the 'second m' is placed outside the attributename
whereas I actually need it to be inside the attribute name, to adress
attributes called "restid1", "restid2" and "restid3" .

And (but thats secondary at the moment) it should be a variable other
than m as m will run up till 16, whereas this piece of code should be
repeated every 4 lines of m.



On Nov 4, 10:10 pm, ben robinson <baltimore....@gmail.com> wrote:
> something like this?
>
> for m = 1 to 4
>
> triallist.SetAttrib m, "restid" & m, randomlist(randompos(m-1))
>
> next m
>

ben robinson

unread,
Nov 4, 2009, 4:47:30 PM11/4/09
to e-p...@googlegroups.com
hi liwenna.

no, "restid" & m should concatinate "restid" and the value of "m" into a single string.  should work.  not promising.

liwenna

unread,
Nov 4, 2009, 4:55:28 PM11/4/09
to E-Prime
Ok! I can hardly wait to try it now...!

I'll report back tomorrow, many thanks in advance!

Have a nice evening,

liw

p.s. this might be a double-post... I either accidentally discarded my
previous reply or sent it to Ben in private... :s

On Nov 4, 10:47 pm, ben robinson <baltimore....@gmail.com> wrote:
> hi liwenna.
>
> no, "restid" & m should concatinate "restid" and the value of "m" into a
> single string.  should work.  not promising.
>

liwenna

unread,
Nov 5, 2009, 7:45:49 AM11/5/09
to E-Prime
Works like a charm!!

Thanks so much Ben. No idea it would be so simple.. just place the
thingy outside the brackets...

Now on to the next step...

liwenna

unread,
Nov 5, 2009, 9:02:42 AM11/5/09
to E-Prime
It is done and works just great... I am quite happy with it.... says
the person who is known for having written out/copy pasted 200
seperate lines of code to create breaks every 20 trials in the past
^.^ (if triallist.sample = 1 then; if triallist.sample = 2 then...
etc).

Now I got one more thing to ask, seeing as I am trying to make this a
decent piece of code... I needed a line that made 'm' (levels of the
triallist) run from 1 to 4 if p (targetidentity) is 1, and run from 5
to 8 if p =2, from 9 to 12 if p is 3 etc.

This is what i came up with: for m = 1 + 4*(p-1) to 4 + 4*(p-1)
But I can imagine that there should be a shortcut for that, like mod
or step.... so... is there? anyone?

Once more thank you Ben!


Greets,

happy liw

David McFarlane

unread,
Nov 5, 2009, 1:24:19 PM11/5/09
to e-p...@googlegroups.com
liwenna,

I applaud you for wanting to improve your coding skills and fussing
over these little details.

FWIW, I would have come up with much the same line, only I might
reduce the math a tiny bit, and I like to add just a few more
parantheses for clarity:

For m = (4*p - 3) to (4*p)

But to be honest I don't know if that is any better or clearer than
what you already did.

Cheers,
-- David McFarlane, Professional Faultfinder

liwenna

unread,
Nov 5, 2009, 2:12:35 PM11/5/09
to E-Prime
*bows*
Reply all
Reply to author
Forward
0 new messages