# Pavlovia Surveys: Page-level timers and one-time random assignment without blocks/triggers?

**URL:** https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314
**Category:** Pavlovia Surveys
**Tags:** timing, randomization, pavlovia
**Created:** [June 14, 2026, 10:56am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314 "2026-06-14T10:56:17Z")
**Posts on this page:** 19
**Page:** 4

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 12:06am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/62 "2026-09-09T00:06:20Z")

</div>

OK, thanks, the credits have been restored now.

If the default value is set in the expinfo dialogue box (e.g. session = 001 as above), will having “session = {{%SESSION\_ID%}}” in the hyperlink override this? Similarly, could I set STUDY\_ID to, say, 42 in the expinfo to differentiate non-Prolific from Prolific participants?

Thanks!

Deborah.

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 1:16am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/63 "2026-09-09T01:16:41Z")

</div>

UPDATE: My student has reset the URL at Prolific as set out above (she had to quit and duplicate the study, as Prolific won’t let you reset it once the study is launched), but now she is getting the same error as before - “RangeError: Invalid array length”.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/8/e8d0e51f3e76013cf739334543a28a3c36fa6f56.png)

Could you PLEASE let me know what is going on here?

**Edited to add** that I have tried this myself - the experiment loads OK, and the first half goes well, but then it crashes immediately after the “progress bar”, so I KNOW it is something to do with the group allocations. (As a reminder, this is where the “feedback” on their performance is presented; group 1’s loop repeats are set to 2-group (so this feedback does not appear for group 2), and group 2’s are set to group -1 (so that they will not appear for group 1)).

**Edited for further info** : Examining the Javascript console shows this:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/4/94c7d7087f0e20fb97bd408b0b31c2f872493e3b.png)

The code is here and I have set it to internal:

> **[Sign in · GitLab](https://gitlab.pavlovia.org/users/sign_in)**
>
> Welcome to Pavlovia's Projects Repository

Thanks

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 6:00am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/64 "2026-09-09T06:00:00Z")

</div>

> [@deborah.apthorp](#):
>
> RangeError: Invalid array length”.

If you create a new study on GitLab then you need a new shelf entry. The shelf entry must be a list with one more zero than the number of groups. (Or the current values from the previous version if you want the new study to know about the existing imbalance)

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 6:27am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/65 "2026-09-09T06:27:34Z")

</div>

Hi Wake,

No, it’s the SAME STUDY on GitLab. It’s just a new project in Prolific.

The GitLab study is exactly the same.

Please can you work out what is wrong with the code?

Thanks

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 9:40am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/66 "2026-09-09T09:40:02Z")

</div>

If it crashes after progress bar then it is probably due to an invalid value for **group** which can’t be interpreted for the number of repetitions.

I recommend that you add `print("group = ", group)` immediately after `expInfo["group"] = group # Add group allocation to data file` in **code\_3** so you can see the value in **Developer tools** without having to go through the card sorting task.

Please also add `print("availableGroups = ", availableGroups, " from ", groupAllocations)` and `print("minAllocation = ", minAllocation)` at the same point.

Once these are added, please let me know and I’ll test it to look at the values in Developer Tools. Please could you also check that the shelf entry is called **group\_allocations** and that the first number in the list isn’t the smallest. [26 8 18] and [6 6 18] is fine, but if you reset it to something like [6 8 18] it will break.

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 10:14am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/67 "2026-09-09T10:14:25Z")

</div>

OK, all done as instructed. Yes the shelf is still [26 8 18] and is still called group\_allocations, .  
I had also concluded that the group number is invalid. While piloting we were able to fix it by resetting all the shelf values to 0. I thought this was due to repeated participant numbers, but have since realised we’re not tracking those.

Cheers

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 10:39am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/68 "2026-09-09T10:39:01Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/e/9ed77ce3230fe87a135c147397a43d3c6503ca41.png)

Please could you add the following to the Begin Experiment tab of code\_3 and let me know so I can try again?

```auto
group = 0
minAllocation = 0

```

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 11:32am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/69 "2026-09-09T11:32:22Z")

</div>

> [@wakecarter](#):
>
> ```auto
> group = 0
> minAllocation = 0
> 
> ```

OK yep done!

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 11:57am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/70 "2026-09-09T11:57:47Z")

</div>

Thanks. I think I’ve located the source of the bug. Please try changing

`minAllocation = Math.min(groupAllocations);`

to

`minAllocation = Math.min(...groupAllocations);`

The error was in the code in my tip (now edited) but the tip already had the fix as a comment.  
_# … needed to indicate groupAllocations is a list_

I also note that this code sets the first value to expInfo[‘session’] which will overwrite the value of session from Prolific.

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 5:19pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/71 "2026-09-09T17:19:31Z")

</div>

Hi Wake,

Unfortunately that does not seem to work. It’s set to autoJS, but if I try to change the Python code on the left, the JS code throws an error and says “Fix Python code”.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/a/9a675a94d71243104e2f33718800427471aab090.jpeg)

Any further ideas? Should I change it to a “both” code component, or JS only since I’m not running it locally?

Yes I had realised about the “session” value; I might include another field in the expinfo for the Prolific session ID.

Thanks

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 9:09pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/72 "2026-09-09T21:09:11Z")

</div>

Thank you. That post has alerted me to a mistake I made when I added local counterbalancing to my working online counterbalance code.

The … should only appear on the JS side, which means that that section of code should be in the Both component.

Begin Routine on the Python side should be

```auto
if os.path.exists(allocations_file):
    try:
        with open(allocations_file, 'r') as f:
            groupAllocations = json.load(f)["group_allocations"]
    except Exception as e:
        logging.warning(f"Warning: Could not load group allocations ({e}), starting fresh.")
        groupAllocations = []
else:
    groupAllocations = []
        
if len(groupAllocations):
    expInfo["session"] = groupAllocations[0] # Add session number to data file
    minAllocation = min(groupAllocations)
else:    
    expInfo["session"] = 0
    minAllocation = 0
    groupAllocations = [0]

```

and on the JS side it should be

```auto
groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values

if (groupAllocations.length) {
    expInfo["session"] = groupAllocations[0];
    minAllocation = Math.min(...groupAllocations); // ... needed in JS to indicate groupAllocations is a list
} else {
    expInfo["session"] = 0;
    minAllocation = 0;
    groupAllocations = [0];
}

```

Hopefully that will sort it. When you’ve made that change I’ll be happy to check the print statements again.

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 9:48pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/73 "2026-09-09T21:48:11Z")

</div>

And presumably, that section comes out of the auto-JS code?

OK, done, could you please check?

Thanks!

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 10:01pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/74 "2026-09-09T22:01:51Z")

</div>

There’s a syntax error. You’ve got

```auto
groupAllocations = await psychoJS.shelf.getListValue({key: ["groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values

```

on the JS side instead of

```auto
groupAllocations = await psychoJS.shelf.getListValue({key: ["group_allocations"], defaultValue: []}); // Get values

```

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 10:04pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/75 "2026-09-09T22:04:27Z")

</div>

Not sure how that happened since I copied & pasted your code directly from here.

However, I’ve fixed that now, can you try again?

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 10:16pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/76 "2026-09-09T22:16:43Z")

</div>

Did you accidentally delete `availableGroups = [] # Define list` from the top of the Auto component? It should be:

```auto
availableGroups = [] # Define list
for Idx in range(1, numberOfGroups + 1):
    if len(groupAllocations) == Idx:
        groupAllocations.append(0)
        availableGroups.append(Idx)
    elif not groupAllocations[Idx]:
        groupAllocations[Idx] = 0
        availableGroups.append(Idx)
    elif groupAllocations[Idx] < (minAllocation + maxAllocationGap):
        availableGroups.append(Idx)
shuffle(availableGroups)
group = availableGroups[0] # group takes positive integer values
expInfo["group"] = group # Add group allocation to data file

```

plus the print statements

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 10:18pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/77 "2026-09-09T22:18:53Z")

</div>

I didn’t think I had, but have fixed now.

Thanks again.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 9, 2026, 10:45pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/78 "2026-09-09T22:45:49Z")

</div>

Looking good.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/e/8ec8ce8707736bf49de776ab06522e4cba3dc74a.png)

It’s ready for you to test.

---

<div class="post-metadata">

### Author: ![deborah.apthorp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/deborah.apthorp/32/134_2.png) [@deborah.apthorp](https://discourse.psychopy.org/u/deborah.apthorp)
#### Post date: [September 9, 2026, 11:20pm UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/79 "2026-09-09T23:20:33Z")

</div>

Fantastic. Just one more quick question - I need a second non-completion URL for participants who don’t meet the inclusion criteria - there’s a different one if they don’t consent which I have in the Settings, but that only allows for one non-completion URL. If they don’t meet the inclusion criteria they should apparently still get paid a small amount, and we have already had complaints about this.

So I’ve added a line in the “end routine” section of the exclusion code routine:

```auto
if ((surveyResponse['block_1/Mental_health_conditions'] !== "0")) {
    psychoJS.experiment.nextEntry();
    psychoJS.setRedirectUrls("https://app.prolific.com/submissions/complete?cc=C14NST0J", "https://app.prolific.com/submissions/complete?cc=CLILLGR8");
    return psychoJS.quit({message: 'Thank you for your participation.', isCompleted: false});
}

```

Before I commit the changes, will this break anything? And will it work?

Thanks!

Deborah.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [September 10, 2026, 5:39am UTC](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314/80 "2026-09-10T05:39:05Z")

</div>

That looks fine, except that it will ignore STUDY\_ID “42”, so you might want to include a nested if STUDY\_ID not equal to “42” around the redirect code.

```auto
if ((surveyResponse["block_1/Mental_health_conditions"] !== "0")) {
    psychoJS.experiment.nextEntry();
    if ((expInfo["STUDY_ID"] !== "42")) {
        psychoJS.experiment.setRedirectUrls("https://app.prolific.com/submissions/complete?cc=C14NST0J", "https://app.prolific.com/submissions/complete?cc=CLILLGR8");
    }
    return psychoJS.quit({message: "Thank you for your participation.", isCompleted: false});
}

```

[Previous page](https://discourse.psychopy.org/t/pavlovia-surveys-page-level-timers-and-one-time-random-assignment-without-blocks-triggers/47314.md?page=3)
