Share feedback, ideas and get community help

Updated 6 months ago

I need to shuffle the order of a block of multiple choice buttons. I trying this:

Block to setVariable
Block with shuffle script
Block to show the options.

function shuffle(array) { array.sort(() => Math.random() - 0.5); } let x = {{options}}; shuffle({x); setVariable({{options}}, x);

does not work
Attachment
typebot.png
K
c
2 comments
try using this script :
Plain Text
function shuffle(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

let x = {{options}};
shuffle(x);
setVariable('options', x);


uncheck "Execute on client?" because the setVariable function is only available in script executed on the server
Attachment
Screenshot_2024-07-02_at_10.40.55_PM.png
thanks. It works perfectly
Add a reply
Sign up and join the conversation on Discord