In this tutorial we will use a variable to control the volume on the office speaker
Variables are an important and powerful component in the StoryFlow authoring system. Variables allow you to store values to be used later and to change things dynamically as the scenario unfolds. In this example, we will use a simple dynamic variable implementation to allow the learner to control the volume of the music in the office.
Step 1: Create a "Speaker" Script
Create a new script called "Speaker"
Add the "Speaker" scene object to the first frame.
Step 2: Add a Menu Option Resource
Create a new frame and add a "Menu Option" resource to it:
Attach the "Menu Option" to the speaker and create two options: Volume Up and Volume Down. Add a Text prompt that says "Adjust Volume":
Step 3: Add a New Frame with an Audio Resource
Create a new frame below the Menu Option frame. Add an Audio resource with the sound attached to the speaker. Choose a song to add from the "Ambient Sound" catalog. This is a repeat of what we did in the "Add Ambience" tutorial, but we are going to add to it:
Step 4: Create a Volume Variable
Instead of setting the volume, we will create a volume variable and allow the learner to control it.
To create a volume variable click on the atom icon beside the "Volume" label, click the '+' to create a new variable, give it a name and click the checkmark to complete:
Now, you should see a variable added to your script:
Step 5: Add a New Frame that Opens on "Close" of the Menu
Add a frame below the Audio. Make it open on "close" of the menu:
Step 6: Add the Newly Created Variable the New Frame
Drag the Volume variable into this new frame:
Step 7: Set Using the Dynamic Content Editor
Click the atom icon in the top right corner of the screen to toggle the editor view:
Watch this video for an explanation of how to set variables dynamically:
Step 8: Add a Replay
After the variable is processed we need to replay the Menu frame so that the new volume value takes effect. Add a "Replay Frame" resource to this frame and replay the frame with the menu it:
Remember to toggle "Ignore Previous" on the condition in the replay frame - if you don't you'll end up with an infinite loop!
Step 9: Add a Default Volume
You might find the volume of the music too loud by default (before it is controlled by the user). Add a new top level frame (not a subframe) and drag the variable into the frame. Set the default value to the level you'd like to be at the start of the scenario.
In this tutorial we set it to 0.1:
Step 10: Launch this Script from the "Ambience" Script
Open the "Ambience" script and launch this new volume controlled speaker from the frame where you had put the audio resource(s) with the speaker music. You can deactivate the audio resource(s) as this new script does the same thing:
Save and test. Now you should be able to control the volume of the speaker with the menu.