Answers to the questions in a challenge: which of two actions is correct. One of the actions had a logical bug in the sequence.
One week ago I posted this challenge
Which action will be functional: A or B?
Why will the non-functional action fail?
Could you ‘fix’ the non-functional action?
Why is using a shared action not considered to be an alternative.
… other ideas?
As promised, here are the answers to those questions (didn’t get any answer to 3 nor 5)
1. Correct action = B
Only action B will be working correctly. Action A will always show the same image, in this case image 4.
2. Why is A failing?
The reason was already ‘hidden’ in the title slide. It is linked to the way advanced (and shared) actions are read and executed in Captivate. All commands will be done, starting with the first decision from top to bottom, then with the second decision (top to bottom) etc until the last command in the last decision is finished. This is different from some programming languages, where a script can be finished before reaching the end, by breaking out of it. Captivate doesn’t support breakout. Hence the importance of screening the sequence of commands in a decision, and the sequence of the decisions themselves. Be also very careful with conditional decisions when using both the THEN and ELSE part! In most cases understanding the logic is easier when you do not use the ELSE part.
Translation of the commands in action A. Remember: the user variable v_click is tracking the number of clicks, there are 4 images to show in sequence and a loop has to be created.
- First condition: What has to happen when v_click =0? First image has to be shown, and since it is a loop, it could be that the last image 4 has to be hidden. Looks logical. However, the problem is in the change of the variable to 1 with the Assign command!
- Second decision: What has to happen when v_click =1? But it is 1 after the first condition (Assign), so this is true, and image1 will be replaced by the image2. Again, the variable will be changed, now to 2 (Assign)
- Third decision: What has to happen when v_click =2? It is 2 after the second condition, image3 replaces image2 and the variable value is changed to 3.
- Fourth decision: What has to happen when v_click =3? It is 3, result is that image3 is replaced by image 4, and the action ends in this situation. Variable is set back to 0. The next click will repeat all the conditions again and result is the same: image4 remains.
3. Fix the wrong action?
Strange that no one answered this challenge. In 2 you did see the cause of mal functioning: the change of variable within a conditional decision. Let us start by taking it out in a separate decision which is not conditional. You cannot use Assign in that case, because that means filling the variable with a fixed value. So I will replace Assign by Increment.
If I want to keep the decision commands as they are in the original action, with one Hide and one Show command, the sequence of the new (5th) decision is important: it has to be at the end, after the 4 original decisions. Result of the fixed action:
4. Shared action not an alternative
One user mentioned that a shared action was not appropriate because it is used only once. Shared actions are not only useful within one project, but have a lot of other advantages as I have mentioned in previous articles: their appearance in the Library, which can be used as external library to re-use the action in any other project is the main reason.
To be a shared action, that is useful for multiple situations, the number of photos should be variable, not fixed to 4. That means an extra variable (v_max). Both actions at this moment have 5 decisions, which is the number of photos + one for the increment (or eventually decrement). It is not possible to make the number of decisions variable however, which means a possible shared action would not be very flexible. It could be useful as template for a future advanced action, since duplicating a decision is very simple. To be used as a shared action that can be used out of the box, it is not suited.
No answers. What about an automatic looping of the photos, using a While loop? Wondering if someone would take that challenge?
Or reversing the logic: use Decrement instead of Increment?