Range replicator

Yasmine El-Shamayleh's Avatar

Yasmine El-Shamayleh

24 Mar, 2021 08:25 PM

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

  1. Support Staff 1 Posted by Christopher Sta... on 24 Mar, 2021 09:20 PM

    Christopher Stawarz's Avatar

    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

  2. 2 Posted by Yasmine El-Sham... on 24 Mar, 2021 11:48 PM

    Yasmine El-Shamayleh's Avatar

    Thanks Chris - this is very helpful!
    Cheers,
    Yasmine

  3. Christopher Stawarz closed this discussion on 29 Mar, 2021 01:27 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac