Mwel help - range_replicator and stimulus_group

Hi Chris,

I was wondering if I could get your help understanding some behavior of my mwel code (attached).
For context, I’m new to mwel (trying to re-code my task, previously coded in Python (moog) to run purely with mwel). The code isn’t finished, I’ve just implemented the trial initialization so far.

I defined the tubes, occluders, and balls stimulus groups using a range_replicator (all reusing the local variable ‘i’, which I declared once on line 47).
In the protocol state ‘Initial’, I then queue the stimuli using while loops to iterate through the individual stimuli in the group.
This code works as expected, but when I replace the while loop on lines 171-175 with:
queue_stimulus(tubes[0])
queue_stimulus(tubes[1])
the behavior is different, specifically the tubes are drawn with the wrong x position.

Why does that happen? I don’t think I understand the order of events regarding the stimulus_group definition and then queuing and displaying. Does it have something to do with how I’m re-using the index i? How can I correct my code so that later if I want to index individual stimuli within the group (e.g. dequeue just one stimulus), the behavior is as expected?

Thanks for your help, and happy holidays!
Sol

(attachments)

balldrop.mwel (6.07 KB)

Hi Sol,

In the expression defining each x_position parameter, you need to put $ before i, e.g.

x_position = (2 * $i - 1) * display_width / 6 

${i} also works. If you just use plain i, it won’t be replaced by the replicator, and the stimulus will instead use the run time value of i. Since i is a local variable, the value it uses will probably be zero.

FYI, you really should use MWorks’ local variables only as the variable parameter of a replicator. They don’t work like local variables in programming languages and are generally not very useful. So, instead of using i as the loop index for while, define another, normal variable for that purpose.

Cheers,
Chris

Thanks Chris!

Best,
Sol