Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Repeating a loop x times

Hey all,

I'm using JavaScript for the current exp, and I have defined a variable called "block_size".

When I'm creating a Loop item I want to set the repeats to be "block_size" times.

I've tried the following but with no success:

set repeat "[block_size]"

Am I missing something? Is it supposed to be different while using JS instead of Python?


Thank you!

Comments

  • Hi @liranpeleg5 ,


    This is indeed a bug in OSWeb. I reported the issue:

    Until the issue is fixed, just let us know if you need help thinking of a temporary workaround by indicating the exact behavior that you want to implement.

    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Thank you for the fast reply!

    I would indeed like to get a workaround.

    Basically what I need to do is to generate a random block_size with value between 2 and 7.

    Then, on a later step in the experiment, I need to define a loop to run block_size times.

    I don't mind defining block_size in a different component if it would work (it's only used in the said Loop item).


    Any ideas? :)

  • Hi @liranpeleg5 ,


    I think something like the following should work:

    • Define the variable "block_count" somewhere in your experiment (for example in the experimental-loop item
    • Prepare 6 different block-loop items with similar content (you could use linked copies for copying the content) and call them something like "block_loop_repeat2", "block_loop_repeat3" etc.
    • Define the respective repeat values as absolute values rather than variables in the corresponding loop items
    • Use Run-if statements (for example in the block-sequence) to determine which block should be run. You could use the following code in the Run-if boxes:
    [block_count] = 2
    [block_count] = 3
    [block_count] = 4
    

    etc.

    I uploaded a working example. Hope this helps!


    Cheers,


    Lotje


    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.