• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Conditional Statement Behavior

New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

I am trying to execute a script (non-Java) and the conditional syntax is tripping me up.

 

I have a button with multiple conditional tabs that I want to play based on the status of a user variable. The Only thing I place in the Conditional tab is an IF for that variable.  The THEN section is all my actions, ending with assigning a new status to my variable.

 

My problem is that no matter what I do, the only tab that runs is the second tab.  All 5 tabs function individually, but only when they are placed in the second slot SEE EDIT BELOW, and regardless of the status of my variable.

 

I suspect that is has something to do with the lack of an ELSE statement, but the only ones that seem applicable are "continue" and "pause", and I have tried both of those without success. The variable is a simple integer that is applied based on which of four buttons on the screen is clicked. I am essentially attempting to recreate an accordion interaction from scratch with custom graphics, so the variable is necessary to know which accordion tab is open.

 

It seems like my tabs should be pretty simple: IF <variable> = 0, execute tab 1 and assign <variable> as 1.  If <variable> = 1, execute tab 2 and assign <variable> as 2.  But as I said, it just plays the second tab over and over on every click. SEE BELOW

 

Any ideas what I am doing wrong?

 

EDIT: My description is slightly wrong after further testing. I cut the decisions down to just three tabs to do some tests. In no case can I get the left (first?) condition to activate. In certain configurations I can make conditions 2 & 3 activate. In certain configurations, only 3 activates. This is blowing my mind. I added a text box to display my variable to ensure that the variable was being assigned properly and it is.  These are not complex actions, either.  It is a combination of showing and hiding elements and running simple entry animations.

TOPICS
Advanced actions

Views

826

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 03, 2020 Jun 03, 2020

Probably a logical bug. Please  post a screenshot of at least part of the advanced actions using the PREVIEW window. You open it using the first button (arrow) in the top right control panel in the Advanced Actions dialog box.

Why do I suspect a logical bug? Because lot of users ignore that, contrary to a programming language like JavaScript and Java (last cannot be used in Captivate) you cannot 'stop' the execution of the advanced action when a correct condition is reached. All decisions (each

...

Votes

Translate

Translate
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Probably a logical bug. Please  post a screenshot of at least part of the advanced actions using the PREVIEW window. You open it using the first button (arrow) in the top right control panel in the Advanced Actions dialog box.

Why do I suspect a logical bug? Because lot of users ignore that, contrary to a programming language like JavaScript and Java (last cannot be used in Captivate) you cannot 'stop' the execution of the advanced action when a correct condition is reached. All decisions (each with a condition) will be done in sequence. Since you are changing the value of the variable within a condition, that could lead to overriding previous decisions. It has been quite a while that I demonstrated this problem in an old post, with an example which is still SWF-based:

http://blog.lilybiri.com/blog-after-posterous-clickclick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Yes - order of operations is important.

This is especially true if part of your action is to modify the variable after it has been checked.

 

if  (variable==0) {

do something;

set variable to 1;

}

 

if  (variable==1) {

do something else;

set variable to 2;

}

 

Just look at the sequence in the short example above.

The code will execute in the order it is written.

If we start at variable = 0, the first if statement will execute which means it will set the variable to 1 and render the following if statement as valid, causing it to execute as well right after the first is finished.

 

It isn't that the first block fails to execute - it is that you have executed something else afterwards.

 

You can use multiple if statements without an else portion but you do need to be careful with how you call them and what you call them to do.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

I suspect you are right and am going to play with this.  I have edited my original post after some experimentation and included screenshots, but it makes sense that this is what is happening. If it sets it to 1 and also has something happen with 1, that happens immediately as well.

 

So, since the script executes from left to right, does that mean as long as a condition only sets a variable to a value found in a condition that is to its left, that it will work properly?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Please insert the screenshots, do not attach them which means I need to download the attachments which I don't like to do for several reasons.

Indeed, that is what I tried to explain. There is no equivalent of the CASE functionality in JS.

Reason why I asked you for a Preview of the advanced action. It could even be possible to help with an alternative.

Best result with multiple decisions is when each of the decisions is mutually exclusive. I bet it would help if you did NOT change the value of the variaible inside a condition, but in a standard deeision so that it will not be changed at any moment. Have multiple examples on my blog.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Screenshots probably aren't necessary since you picked it out immediately.  That is what is happening.  I can play with it on my own to figure out a workaround from here.  Thank you for the help.

 

So there is no simple way to force a script to stop? Not necessarily on finding a condition, just a way to stop it at all would probably work fo rme.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

This is what is happening.  Is there a way for me to force the script to stop after a true condition is found?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Sure - I would argue that this is more complicated through advanced actions than with pure code.

Think about my above example in this way...

Where "else" means, if the above statement is not true...

 

If (some statement is true) {

do something;

}

Else {

do this instead;

}

 

Only one of these blocks will execute when called as the initial conditions will either be true or false.

Hopefully that makes some sense the way I wrote it.

 

Another trick is to put them in reverse order.

 

if (variable==1) {

do something;

set variable to 2;

}

 

if (variable==0) {

do something else;

set variable to 1;

}

Looking at the same example in reverse..

If we start with variable = 0, Since the if statement to check the variable =1 has already executed it will not be run again when it is changed to one in the next block.

 

A few ways to skin the cat as it were but maybe that will help you sort out the logic.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Some clarity here.

In both cases I offered - nothing is truly being "stopped" as it were.

All statements are still evaluated but our logic gymnastics can still help us do what we need by giving that appearance.

 

Of course, you'll just need to work out the specifics.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Just wanted to pop in and say thank you and that I went in a third direction to solve it. My problem was that I essentially need a "toggle" and was trying to use a variable and, well, toggle it, but that was causing the cascade as the variable went between 1 & 2 like so:

 

IF 1 set 2

IF 2 set 1

 

Obviously in either configuration it's wrong. I think what I did was what you were indicating in the second half of your suggestion.

 

I added a third state, 0, and turned it into a functional spacer so 2 never goes directly to 1.

 

IF 0 set 1

IF 2 set 0

IF 1 set 2

 

I didn't even have to add any actions, I just had to reroute it back to the start and reassign the variable.

 

Thanks again for all the help!

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Glad you figured it out.

 

In the case of a toggle - I just go this way.

 

If (variable==0) {

turn on;

variable=1;

}

Else {

turn off;

variable=0;

}

 

Remember only one of those will be true each time the button is clicked.

Only the true one will execute.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Simpler yet you could use the simple action on the side for your button called   Toggle

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

LATEST

That is the reason why I asked to see the action. Many times in this forum I have simplified very long threaded advanced actions by a different approach, or make it much smoother by using shared actions instead of advanced actions. If you had only mentioned the word 'toggle', I would have pointed to:

 

http://blog.lilybiri.com/1-action-equals-5-toggle-buttons

 

It is a very flexible shared action,  and very simple.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources