Use a dynamic variable to change the volume of the 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 workshop.
Step 1: Create a "Speaker" Script
- Create a new script called "Speaker".
- Open the new script.
- Re-name the New Frame "Scene objects".
- Open the Catalog icon and choose "Workshop Objects".
- Drag the Speaker object to the frame:
Step 2: Add a Menu Option Resource
- Create a new frame (from the Main Frame) and add a "Menu Option" resource to it:
- Under "World Objects", choose "Speaker".
- Under "Prompts", choose "Text".
- Add a text prompt that says "Adjust volume".
- Under Input Option/Menu Option/Text, enter "Volume Up".
- Under "Event", choose "Add Custom Event".
- Enter the text "Volume Up" and select the checkmark to save your Custom Event.
- Ensure your "Volume Up" event shows in the Event area (use the dropdown to select it).
- Scroll back up to "Input Options" and click on the "+" icon to add another option.
- Under the "Input" dropdown, choose "Menu Option".
- In the text field, enter "Volume Down".
- Under "Event", choose "Add Custom Event".
- Enter the text "Volume Down" and select the checkmark to save your Custom Event.
- Ensure your "Volume Down" event shows in the Event area (use the dropdown to select it).
Did you get stuck? Check out this video:
If the video is too small, mouse over the bottom right and click on the fullscreen icon after you hit play.
- Re-name this frame "Menu Option".
- Save your script.
Step 3: Add a New Frame with an Audio Resource
- Create a new subframe below the Menu Option frame and re-name it "Audio".
- Click on the Media icon on the far right and choose "Workshop Music".
- Drag the music (Audio Resource) you'd like to use over to the frame.
- The anchor is the speaker.
Step 4: Create a Volume Variable
Instead of setting the volume, we will create a volume variable and allow the learner to control it.
- 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 to 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.
If the video is too small, mouse over the bottom right and click the fullscreen icon after you hit play.
- Save Script.
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.
- Toggle editor view back:
- Add a "Replay Frame" resource to this frame (the same frame where you created this dynamic content tree) by dragging it from the Resources area to the frame
- Choose the Menu Option frame (because that is where the menu option is).
- Remember to toggle "Ignore Previous" on the condition in the replay frame - if you don't you'll end up with an infinite loop!
- Scroll up to the Object Event condition and check the box.
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).
- Re-name the frame "Default Volume".
- 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.
- Launch this new volume-controlled speaker from the frame where you had put the audio resource with the speaker music.
- You can deactivate the audio resource as this new script does the same thing:
If the video is too small mouse over the bottom right and click the fullscreen icon after you hit play.
- STOP: Save and test. Now you should be able to control the volume of the speaker with the menu.
In the Headset
This is what your scenario will look like so far: