Help to improve a quiz skill (G Sheets integration based)

Hi everybody.

I need help!

I created a quiz skill with random questions retrived from a Google Sheet.
I add the G Sheets integration, I left empty the “Value to match” field in “With settings” section and mapped the output. Skill works like a charm, but I need to avoid the repetition of already used questions.

I’m not figure what kind of code I need to use to exclude the already used questions from the G Sheets integration block random row choice, and where I want to put it.

I already tried to adapt the code in this tutorial (https://voices.app/?p=1747) but without success.

I’m going crazy, so every help or advice will be really appreciated! :smiley:

Hi fortarrigo,

I don’t use the Voiceflow Google Sheets Integration. However I reviewed the Voiceflow tutorial and watched the video.

You might try the idea below, and see if it works. Just be aware I haven’t tested this.

Let’s suppose you have 100 questions in your Google Sheet (GS). The first row in your GS would be your column headers. Rows 2 through 101 would be your quiz questions and other corresponding values such as the answers.

The idea is to use the GS Integration feature, and the “retrieve data” option. In the retrieve data option, you can configure “with settings” with Row Number = 2 (which would be the row with your first question). You can see this in the tutorial video, at 3:40. However instead of using “2”, we would use a variable which stores a random number instead.

Flow:

  1. Create a variable to store the retrieved question. For example {quiz_Question}.

  2. Create any additional needed variables for values such as the corresponding answers.

  3. Create a separate variable for storing a random number which will be the generated random number, incremented by 1. It can be named something like {RN_randomNoPlus1}. The generated random number will be 1 through 100, but the row numbers in the GS are 2 through 101.

  4. Add the code for a non-repeating random number between 1 and 100 (per the tutorial you referenced in your original post). This should result in storing generated random numbers in a variable, such as {RN_randomNo}.

  5. Add a SET block after the CODE block which generates the random number. Set {RN_randomNoPlus1} = {RN_randomNo} + 1. This will result in having random numbers between 2 and 101. You could also accomplish this by adding a line of javascript in your CODE block if you want to avoid this SET block.

  6. Configure the Integrations block with Google Sheets Integrations, using the “I want to retrieve data” feature.
    a. In the “with settings” section, set Row Number = {RN_randomNoPlus1}
    b. In the “mapping output” section, map the column with the question to {quiz_Question}
    c. Map the output of any other needed values from the row, such as the answers.

  7. Use the variables with the retrieved quiz question, answers, etc. If the user would like to continue, loop back to the code block for the next quiz question.

Good luck! Let us know if this works.

Hi @Mark!
Thank you very, very much!
Now the path It’s clear!

I’ll try and let you know if it works.

Thanks again!

@Mark your solution works like a charm!
Thank you!

Have a nice day (if you are US based) :slight_smile:

Awesome! Glad to hear it worked!

Thanks, and you have a nice day/evening as well :slight_smile: