Populating variables based on button states

Mar 14, 2023

Hello!

I have a storyline slide that contains 30 words. I want the user to be able to choose 10 of the 30 words. Choosing the words will populate the variables so they can be taken through to the next slide. But I am struggling as I am unsure if it can solely be done with the SL triggers/variables.

For example -  When the state of button 'Acceptance' is selected, this would need to populate the variable 'Choice 1' with the word Acceptance, only doing so if that variable is blank. If 'Choice 1' is already populated then it would have to populate 'choice 2' - but again only doing so if it is blank. And so on and so on.

Has anyone got any examples or offer any help? I fear it may be a JS job!

6 Replies
Phil Mayor

It can be done with just triggers and variables but it is going to be a lot of triggers and conditions.

You will need 10 triggers on each button with conditions, e.g.

Set Choice1 to Acceptance if Choice 1 on condition is equal to blank

Set Choice1 to Acceptance if Choice 1 on condition is not equal to "Choice" AND Choice2 is equal to blank

Etc....

You will need to have triggers to remove the value if they deselect it (although I would be tempted to lock them, by setting to disabled instead of selected, and then. have a reset button). 

Rachael Mordecai

Thanks for replying Phil!

I don't think that will work- as adding them triggers causes everything to populate.

I have a working example of what I need using html/JS if this explains it better. I think because it needs to be dynamic I will need to use JS. Just can't seem to get this to work in storyline.

https://jsfiddle.net/gmhxf9na/

Chris Riley

I was able to get the simple case working, with no ability to "unselect" a value. It is a lot of triggers and a lot of typing, even for my proof-of-concept with only 5 buttons and 3 selections.

My triggers with just 3 options look like this, but you'll need 10 triggers for each button:

With each subsequent choice, you continue the pattern of

    A) Checking that the previous choice has been filled out

    B) Checking that the clicked button has not already been used, and

    C) Checking that the choice is not already filled out.

(B) requires an additional condition for each choice, so the 10th choice would require 9 conditions to check if it's been used in any of the 9 prior choices.

I also have a Javascript solution here, and I'm working on a blog post with an in-depth explanation of each!