How do you dynamically update variables in a loop | XM Community
Skip to main content
Solved

How do you dynamically update variables in a loop

  • April 19, 2022
  • 4 replies
  • 100 views

Forum|alt.badge.img

Hello
I am building an experiment that involves repeated trials where I provide 3 input numbers (VAR1, VAR2, VAR3) that are each a random number between 1 and 25. An output is calculated on the subsequent page.
For each trial, I would like VAR1, VAR2 and VAR3 to recalculate as newly generated numbers. I would like to save these as well as the subsequent page of model output for each trial.
When I use the loop and merge function at the moment however, every trial is still showing the same original VAR1, VAR2, VAR3 calculated.
How do I get these to dynamically update instead?
Thank you

Best answer by TomG

Pipe them into the loop & merge fields like:
Field1 Field2 Field3
1 ${e://Field/VAR1_1} ${e://Field/VAR2_1} ${e://Field/VAR3_1}
2 ${e://Field/VAR1_2} ${e://Field/VAR2_2} ${e://Field/VAR3_2}
...etc...

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6082 replies
  • April 19, 2022

If you need to save VAR1, VAR2, VAR3 in your response data, you can generate them for each loop (e.g., VAR1_1, VAR1_2, etc.) and add them as fields in your loop & merge setup.


Forum|alt.badge.img
  • Author
  • 2 replies
  • April 19, 2022

Hi Tom, could I please trouble you for a bit more detail on how you can add them as fields in the loop and merge setup? Thank you


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6082 replies
  • Answer
  • April 19, 2022

Pipe them into the loop & merge fields like:
Field1 Field2 Field3
1 ${e://Field/VAR1_1} ${e://Field/VAR2_1} ${e://Field/VAR3_1}
2 ${e://Field/VAR1_2} ${e://Field/VAR2_2} ${e://Field/VAR3_2}
...etc...


Forum|alt.badge.img
  • Author
  • 2 replies
  • April 20, 2022

Thanks Tom, this was just what I needed