Join Anastasia McCune for an in-depth discussion in this video Using conditional actions to affect object visibility, part of Captivate Advanced Techniques.
- In this lesson we're gonna use a different kind of Advanced Action, a conditional action to affect the visibility of things on the screen. Remember that a conditional action does something only if a certain condition is met. For instance, if you've eaten your dinner, then you get dessert, else you have to eat five more bites. We'll be working again in the CFL Wattage project. Here's our scenario. On Slide 2 the learner is asked which CFL bulb wattage is equivalent to a 100 watt incandescent bulb.
20 or 30? We're gonna a variable to store the user's answer. The correct answer, by the way, is 23. Then on the next screen, we'll test and see if the user selected 23, then display the Yes, 23 is correct message. We'll hide the Sorry, 20 is not correct message. If they chose 20, which is wrong, we're gonna hide the You are correct message and show Sorry, 20 is not correct. So we're going to start on Slide 2 where the user is asked to select which answer they think is right.
To hold what answer they select, either 20 or 23, let's create a variable. So I'll go to the Project menu and choose Variables. We already have a couple of variables in this project from the previous lessons. I'll click Add New and give this variable the name of userWattageAnswer. I'll give it an initial value of 0 and then type a Description. Now I'll click Save and the variable now appears in the list of available user-defined variables below. That's great. I'll choose Close.
Now that we have the container that will store the user's answer, we have to stuff the value of either 20 or 23, depending on what button the user picks, into that variable. Let's start with if the user chooses 20. So I'll go to the Project menu and choose Advanced Actions. We're not checking for any particular condition to be met here. We just want to dump the user's answer into the userWattageAnswer variable. So this is gonna be a standard action, not a conditional. I'll give it the name answer20.
I'll double click on the first line in the Actions area, and from the drop-down, choose Assign. I'm going to assign the variable called userWattageAnswer, so I'm gonna choose that from this drop-down, with the Literal value of 20. So basically stuff the value of 20 into userWattageAnswer. With that, I'll click Save As Action. My script has been saved successfully, and I'll click Close.
Now we have to kick off this script when the user selects the 20 button. So I'll select the 20 button on the screen, and in the Actions area in the Properties panel, I'm gonna change On Success from Go to next slide to Execute Advanced Actions. The Action I want to execute is answer20. We're gonna preview my project from this slide. I can click the 20 button and presumably our Advanced Action is executing. That's great, but we're stuck on this slide.
There's no way to advance to the next screen and see the answer. We could add Click to Continue button to this slide as a way to solve this. We could also add to the Advanced Action we just created so that first the value of 20 is put in the variable and then we advance to the next slide. That seems like the better user experience since the user only has to click one thing instead of two. So let's do it. I'll close the preview. Back in Captivate with the 20 button still selected, I'll find my way back to that Actions accordion.
I'm gonna click on this little Advanced Actions button next to the Script drop-down to open up the Advanced Actions panel again. Remember also that we could've gotten to the same spot by going to the Project menu and Advanced Actions. So we want to make our change to the answer20 action. So I'll choose it from the Existing Actions drop-down. When I double click on the second line, and I'm going to select the Action of Go to Next Slide. The box on the left has a green checkmark telling us that Captivate thinks is a complete action, so that's great.
We're gonna update the Action and Close. Now let's preview from this slide again. This time I'll choose 20. The value is stored in memory, and we move on to the next slide, so that looks good. So we need to have almost the exact same thing for the 23 button. I'll select it. In the Actions accordion, change the On Success drop-down from Go to Next Slide to Execute Advanced Actions.
The thing is we don't want to run either of these actions. We need a new one. So I'm gonna open up the Advanced Actions panel. Instead of writing a new script from scratch, we can copy and modify the answer20 script. So I'll select answer20 from the Existing Actions drop-down. Now I'll choose the Duplicate Action button from the very upper right. I'm gonna the name of my new action to answer23. All we have to do is change this to assign userWattageAnswer with 23, so I'll change it to the Literal value of 23.
So this script assigns the variable, the value of 23, moves us to the next slide. This action looks good. I'll click Update to save the changes and Close. Now I'll choose the 23 button. We're already executing Advanced Actions. I want this one to run answer23. This slide is done. I'm gonna save my project and move on to Slide 3. Here's where we'll create a new conditional action to pick which one of the feedback messages to display.
We could jump right into creating the action, but first I'm gonna select one of the feedback messages. In the Properties panel deselect Visible in output. I'll do it for the other feedback message as well. We can still see these while we're here working in Captivate, but if I preview from this slide, you'll see that they're now both invisible. We probably don't need to do this since the script is going to show or hide the messages so quickly that we'll never see what their initial state was. But turning off the visibility to start with just makes doubly sure that our learners don't see anything displayed when it's not meant to be.
I also just wanted you to know that it exists in the event you have something in a future project that you want to start off invisible and then turn on later. Also notice in the Properties panel that these two text captions have descriptive names of youAreRight and youAreWrong. When you add items to the screen in Captivate, by default they're given not very helpful names, like Button_6 is what Click to Continue has. Or Image_12 is what the picture of the lady has. Changing the name makes it easier to identify items when we write our script.
It also, by the way, changes the names displayed in the timeline. For instance, I can see my youAreRight and youAreWrong text boxes right here, and the name is indicated here in the timeline. That can be helpful when you have a lot of items on a slide and want to tell at a glance which one is which in the timeline. Anyway, let's write a script for this screen. So I'll go to Project menu and choose Advanced Actions. This time our action is going to be a conditional action. We'll be doing something only if a specific condition is met.
I'll give this action the name displayAppropriateMessage. The correct answer to this question, again, is 23. So what we're going for in our script is if userWattageAnswer is equal to 20, show youAreWrong, hide youAreRight, otherwise show youAreRight, hide youAreWrong. So let's get this entered in. So on the first line under the If area, I'm gonna say if my variable called userWattageAnswer is equal to the wrong answer, if it's equal to the literal value of 20, then in the Actions area, I want to Show youAreWrong.
I want to hide youAreRight. So what we've got is if the user selected 20, tell them they're wrong, otherwise ... So down here in the Else area, I'll click on the Else to open it. We know they selected 23, that's correct, so we want to Show the text caption called youAreRight and Hide the text caption called youAreWrong. So you can click on the If and Else headers to view what you've got in each section if you need to.
I think we're done with this script, so I'm gonna say Save As Action, and now we'll Close. I want to point out that we set up our script to check on the value of 20, but there's no reason we couldn't have set it up the opposite way and checked on the answer of 23, then displayed and hidden the appropriate text boxes that way. Either way would work. So our script is ready. The only thing left is to figure out how to kick it off. Well, we want to turn these two text captions on and off as soon as the user reaches this slide so they see the correct thing.
So then we could attach the action directly to this slide. So I'll make sure I've clicked somewhere on Slide 3 itself, and then in the Action accordion in the On Enter drop-down, I'm gonna change it from No Action to Execute Advanced Actions. Which script we want to run is displayAppropriateMessage. Before we test, I'm going to move the Sorry, 20 is not correct text caption on top of the other one. That way, they both appear in the green bubble whenever they're displayed.
With that, we'll preview our project. So the first time through I'll select the wrong answer of 20, and we get the appropriate error message. Now I'm gonna Rewind to start over. This time I'll choose the correct answer of 23, and we're told that 23 is correct. So our script is working. So now you've seen how you can make logical decisions in your project by using conditional actions.
You've also seen how you can affect object visibility by choosing to make things visible in the output in the first place, and then also using Advanced Actions to show or hide.
- Recording multiple types of projects at once
- Creating and applying custom styles
- Using templates and skins
- Working with master slides
- Aggregating multiple lessons
- Creating and populating question pools
- Capturing and displaying a user's name
- Using conditional actions to control object visibility and navigation
- Choosing and configuring interactions
- Using Text-to-Speech to create voiceovers
- Recording a video demo
- Adding accessibility features to projects