Re-evaluating expressions on every button press? (block random assignment question)

Hi folks,

I am using Wake’s Post as a workaround to displaying 1 of 4 possible pages in a randomised way to participants.

I have created 2 variables in the main survey logic tab under Calculated Values:

randNum, which is set to random()*4+1 (so random number between 1 and 5)

condition, which is set to iif({randNum} > 4, "cond1", iif({randNum} > 3, "cond2", iif({randNum} > 2, "cond3", "cond4")))

I have a welcome page that I want everyone to see and then 4 pages with questions on them. I want to display one of those 4 pages to participants depending on their condition (cond1, cond2, cond3, or cond4).

The expressions work, BUT every time the user ticks a box, or dropdown or whatever the interaction, the calculated values seem to re-execute, therefore causing weird behaviour. Am I putting these expressions in the wrong place, or is there a way to set these values once at the start of the survey and not re-execute?

I did read in the SurveyJS docs that expressions re-evaluate when the information used in them changes, but I’m not changing any of them…I don’t think.

Any help is appreciated.

My JSON can be found below in case that helps.
four-way.json (2.0 KB)


I can’t see your expression question but I can see something called ranNum in the json code. How did you create it? I’ve just spotted randNum in your survey settings under logic, which may explain why it keeps changing. Try adding two expression questions on the first page, then make them invisible and make sure that the Data Clear if Hidden is set to none

Hi Wake,

Moved the setting of the expressions off the Logic → Calculated Values pane and into Expression questions on page 1. However, I still think I’m getting it re-evaluated on every click.

it seems to randomise, but when I tick one of those questions on the page, it takes me back to the start and gives me a new condition :confused:

Some new JSON attached

newRandom.json (2.0 KB)

Just a quick update on this Wake, it doesn’t seem like I’m taking the right approach to randomise people to conditions (pages). Wherever I have random() it re-executes that code on every interaction with the survey, which means they change conditions on every press.

To fix this, is there a place I can execute an expression once and lock it (like a constant) and then assign them to a group based on this?


Is there another way to randomise people to conditions that I have not figured out yet?

Best wishes,


I’ll have to raise this as a bug. I’m sure it was working but not any more.

Personally, I’m now randomising in PsychoPy and embedding surveys. However, the survey can’t yet read the randomisation so the effect of the randomisation has to either be a different survey (selected via nReps in a loop around it) or within a PsychoPy routine.

1 Like

Thanks Wake. Is there a github issues page for Pavlovia Surveys?

I’m not sure. We use ClickUp within the team so I’ve created a bug report there based with my own demo of the issue: Pavlovia Survey

I’m also noting (in a separate bug report but with the same demo as evidence) that you have to do something to random() to be able to use it.

Although this hasn’t been fixed yet, I’ve just written a workaround

Hi Wake,

im getting 404s when clicking these links, can you perhaps share your demo project so i can see under the hood?



The link is now (I updated the original post but it didn’t update the link).

I’ve made it public so you can access the code from