Tip 4: Decisions (Advanced/Shared Actions)

Intro: Decision (tab)

The Advanced Actions dialog box in its default setup for a new action, shows  3 decisions with the generic names 'Untitled-1', 'Untitled-2' and 'Untitled-3'.It is possible to replace the generic names of course. In this screenshot they are marked by a red rounded rectangle. 

On top of the decisions to the left you see three buttons, which allow to Add decisions, Remove or Duplicate a decision.  There is no real limit to the number of decisions within one advanced/shared action. 

In the center above the decision names you find two buttons (blue rounded rectangle in screenshot above) which allow to change the sequence of the decisions by moving them to the right or to the left. That sequence is very important! First rule to remember when starting with Advanced/shared actions:

"All commands (actions) within an Advanced or Shared actions are always executed when the action is triggered. They are done always in the same sequence: top to bottom within a decision, left to right in the decision sequence."

Workflows which exist in most programming language to skip part of a long script do not exist. Forgetting about this first rule often leads to logical bugs!

Each decision can be converted into a conditional one by checking the option 'Conditional tab'. The word 'tab' is used there, but I largely prefer the original name 'decision' because Captivate has tabs in many locations, not only in the Advanced Actions dialog box. For a conditional decision, you have the choice between the classical 'IF-THEN-ELSE' which has two sets of commands (THEN, ELSE). One set be will chosen based on the result of the condition.
The WHILE condition leads to an infinite or finite loop. The set of commands will be executed after 1 second, based on the condition:
I would like to offer some tips now both to avoid problems and to streamline the choice of decisions taking into account the limitations mentioned before.

Tip 1: Combining standard and conditional decisions

This tip is based on my experiences with consultancy jobs and answering on the forums.

When starting to create advanced actions it often happens that too much commands are pushed into one conditional decision. I recommend to reflect: which of the commands (actions) have to be done independently of the condition? Those commands will appear in both  THEN and ELSE sections. In that case, take them out and put them in a separate non-conditional decision. 

Same recommendation when using multiple conditional decisions, if some commands appear in all of those conditions.

Example

This scenario appeared several times for debugging on the forums: 'Looping through a number of images  with their text, and showing a Next button after the first loop'.  The loop in this example is done with show/hide, not with a multistate object (which is easier however). Look at the original advanced action, meant for 3 images:

The second/third image and text are hidden in Output. The first image and text are visible. The result of this action is that the loop will not work, that each click on the button will always show the third image, while the counter will indeed loop and the Next button will appear as wanted. Reason is that the last conditional decision overrides the other decisions. Compare this with this solution:

In this action:

  • Texts and Images were grouped, to allow taking out the Hide actions from the conditional decisions.
  • A non-conditional decision was added before the conditional ones to hide the groups before the showing the text/image corresponding with a specific variable value. Moreover the (absolute) Assign command was replaced by Increment.
  • The conditional decisions show text, image. The last one needs also to show the Next button and reset the counter to its original value, which is 0. In that case you need Assign of course.


Tip 2: Multiple conditional decisions - make them mutually exclusive

When you have multiple conditions decisions in sequence (remember the sequence rule), avoid using the ELSE parts. You'll have less possible problems when using only the THEN part and write a conditional decision for each possible situation. If you use the THEN parts, there is a big chance that a later decision will overrule what has been done in the previous ones.

Eventually it is possible to use an ELSE part, but only for the last decision. You need to double-check if that THEN part will not mess up with previous decisions.

Example:

Using the same situation as for the first tip, there is no way to use the ELSE part of the decision 'Second' to replace the decision 'Third'.  The complete action would then look like this:

The result would be that the First decision would never be done, the second image/text never pops up and the Next button will appear after having viewed only the first and third image.


Tip 3: working with Tracking Variables

The first tip already showed how dangerous it is to change the value of a tracking variable within a conditional decision, if you have more than one of those decisions. In most cases it is safer to keep the value change in a non-conditional decision. You are probably aware of the three ways to attribute or change the value of a variable:

  • Assign: which I label as the 'absolute' way, and is valid for both strings and numerical values.
  • Increment/Decrement: often used when you also need a counter.
  • Toggle: typical for a Boolean variable, which is used for an On/Off situation. 

Here are two situations where you will need to have the variable value change within both parts of a conditional action (THEN and ELSE):

3.1 Toggle button action

Such an action will often have only one conditional decision and uses a Boolean variable for tracking. Have a look at this script, which will show/hide an object:

3.2 Non-eternal loop (WHILE)

Such a loop needs to have a way to stop looping. That is done with a tracking variable which needs to be changed within the actions which need repetition. Here is an example from a dice game. The dice number (random) is stored in a variable, and another variable stores the number of stairs which need to be climbed. The screenshots shows only the While decision of the action.