Range replicator

Hi Chris -

Another quick question as I learn the ropes!

I’m adapting code from Marianna at NYU that uses range_replicator to determine a range of x/y positions for a stimulus, as follows:

list calibration_list (selection = random_without_replacement) {
          range_replicator (
              from = -4
              to = 4
              step = 2
              variable = stm_selector_x
              ) {
              range_replicator (
                  from = -4
                  to = 4
                  step = 2
                  variable = stm_selector_y
                  ) {

I want to remove the hard-coded -4 to 4 range – and replace it with a user defined range in the variables window. I found somewhere in the discussion board that values in the range_replicator must be pre-defined and must have a local range, but I’m not sure where that definition goes or how it’s implemented.

For example, I tried something like this (but it didn’t work):

In the variables section, I added:

var area_sampled = 5 (
    scope = local
    logging = never
    )

Then in the list section I added:

range_replicator (
                  variable = area_sampled
                  from = -area_sampled
                  to = area_sampled
                  step = 2
                  variable = stm_selector_x
                  ) {

Tips?

Thanks!
Yasmine

Hi Yasmine,

As I snarkily note in the user manual, replicators are tricky to use. The main reason for this is that they’re expanded when the experiment is loaded, not when it runs. While you can, with a little coaxing, convince a replicator to accept variables in its parameters, the replicator will only ever use the load-time value of the variable. Changes to the variable’s value made after the experiment loads (either within the experiment code or via MWClient’s variables window) have no effect on it.

For this reason, it makes more sense to use expression macros for this job. For example:

%define area_sampled = 5

and then

list (selection = random_without_replacement) {
    range_replicator (
        variable = stm_selector_x
        from = -area_sampled
        to = area_sampled
        step = 2
        ) {
        range_replicator (
            variable = stm_selector_y
            from = -area_sampled
            to = area_sampled
            step = 2
            ) {

I’ve attached a short example experiment that demonstrates this approach.

If you need to be able to change area_sampled after the experiment loads, then range replicators aren’t going to work. Instead, you’ll need to loop explicitly through the desired ranges in your experiment. (If you need an example of this, let me know.)

Cheers,
Chris

Attachment: range_rep.mwel.zip (839 Bytes)

Thanks Chris - this is very helpful!
Cheers,
Yasmine