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

Conditional Action Numeric Comparison Problem

Explorer ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

I read Rod Ward's long blog on conditional actions in Captivate, which seems to be telling me if I have a user variable with a numeric value and I'm comparing it with a literal value of -1 to see if they are equal, it should work properly because, as Rod says, "what happens under the hood is that strings are first converted into numeric values before being evaluated".  However, it's clearly not working.  This is what I have for the IF condition:  variable_name  is equal to  -1.  The value of the variable reported in the Console (via a call to cpAPIInterface.getVariableValue()) is -1.  And yet the conditional action is performing the ELSE action instead of the IF action, as if it thinks the variable, whose value is -1 is NOT equal to -1.  Surely Captivate is not so lame that it can't handle the minus sign on the -1!  Does anyone have an idea why this would not be working?

TOPICS
Advanced

Views

1.0K

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

Explorer , Apr 21, 2016 Apr 21, 2016

I was waiting a bit to see if any of the other advanced/prolific contributors would chime in with an opinion opposite to the one Lilybiri expressed, but no one has.  I do appreciate Lilybiri's offer to help.  For a while I believed her assertion that Captivate couldn't handle

    if varname  is equal to  -1

correctly.  I created a very simple test case to attempt to confirm it, one that had nothing else going on at all to muddy the waters.  I was surprised when it worked just fine comparing a vari

...

Votes

Translate

Translate
Community Expert ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

What do you really want to check, please?

Captivate cannot see 'negative' numbers, will see the '-1' as '1', at least AFAIK.

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
Explorer ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

I really want to check to see if the value of the variable is equal to the number -1.  We set it to one of three different values, -1, 0, or 1.  In this case, I need to do one thing if it's -1, and something else if it's 0 or 1.  We are setting it to -1, which obviously works, since the Console reports its value as -1.  If the comparison happening in the conditional action truly can't handle that, I can obviously check instead if the value is 0 or 1, and do the current ELSE action, and OTHERWISE do the current IF action, to handle the troublesome -1 case.  It's pretty sick, though, if I can't simply ask Captivate if my variable is equal to -1 and have it work.

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 ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

I have a workaround, that I just double-checked in Captivate, similar to what I described in this article:

Where is Null? - Captivate blog

I created a user variable v_negative with the value = -1.

Using the condition "IF var is equal to v_negative" will work if var has the value -1.

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
Explorer ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

Thanks for your help. 

So, we're actually saying that it's OK to give a user variable a numerical value of -1 (or probably any negative integer), but the conditional action machinery is actually so poor that a simple condition like

     IF var_name is equal to -1

simply won't work as we would reasonably expect it to work?  As a programmer, I find this pretty shocking.

I was wondering about the "contains" comparison operator.  Would Captivate think the variable "contains" the string "-1"?

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 ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

I just tried to help because I know about those issues with numerical values below or equal to 0. Try out 'contains'. Do not forget that I'm just a user as well, think it is better to find workarounds than spending time ranting. The other approach is to use JS. Just my personal opinion.

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 ,
Apr 20, 2016 Apr 20, 2016

Copy link to clipboard

Copied

Captivate's Advanced Action functionality is NOT a full-on programming environment and comparing it or expecting to work the same way as almost any true programming language is going to cause you no end of frustration.

It's only VERY rudimentary scripting designed specifically for a non-programmer audience who have most likely NEVER previously created event-based interactivity.

Having said that, most Captivate users never use even a fraction of what can be accomplished with Cp user variables and advanced actions.  So, to my mind, even though I would dearly like to see more power added to Advanced Actions, I'd have to say that Adobe didn't do too bad a job of designing this side of Captivate.

At one end it gets bagged by newbie users as too complex, and at the other end of the spectrum it gets bagged by programmers as being too simplistic and limited.  So I guess that means 'on average' it's almost perfect for the users caught in the middle.

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
Explorer ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

I was waiting a bit to see if any of the other advanced/prolific contributors would chime in with an opinion opposite to the one Lilybiri expressed, but no one has.  I do appreciate Lilybiri's offer to help.  For a while I believed her assertion that Captivate couldn't handle

    if varname  is equal to  -1

correctly.  I created a very simple test case to attempt to confirm it, one that had nothing else going on at all to muddy the waters.  I was surprised when it worked just fine comparing a variable with -1.  Then I noticed other places in our existing Advanced Actions that already rely on it working properly, and they have been working as expected.  So I was banging my head against it for a few more hours trying to figure out the real reason it wasn't working and then I discovered there were TWO active click areas on that slide, one of which activated the AA I had been wrestling with, and another which hadn't been modified but needed to be, which was performing the same action as the ELSE action of the other one.  So I basically discovered it wasn't a problem with checking against -1 at all, as it originally appeared, but of executing the wrong AA.

Also, if Rod's blog comment is correct ("what happens under the hood is that strings are first converted into numeric values before being evaluated"), then it SHOULD work just fine to compare negative numbers.  And it certainly seems to, now.

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 ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

Will double-check. Are you on CP9?

Yup, it worked! You are correct.  I have confused the fact that you cannot calculate with negative numbers, but the 'literal' value in a conditional action is, AFAIK, always interpreted as a 'string', which means that the variable is compared with the literal text '-1'. If you start to ask if the variable is less than -1, you are stuck because CP cannot handle negative numbers. But it can compare a literal text which has a - (is not interpreted as a negative sign, but as a character). Slapping my head!

Sorry for the confusion

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
Explorer ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

Yes, CP9.  I should have said....

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
Explorer ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

No problem.  I appreciate having access to your expertise and that of the other contributors here. 

But I still wonder about the way this particular case works.  Rod's assertion and yours seem to be in direct conflict.  You're saying the comparison is, of necessity, a STRING comparison.  He is saying that strings are converted to numeric values and THEN compared numerically.  If he's right, then a condition like

     IF varname  is less than  -4

ought to work just fine, provided that varname's contents are likewise converted to a number before the comparison is made.

But if your assertion is correct, then, clearly, such a comparison would not 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 ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

Yes, I understand you see a conflict. Rod is a programmer, he is probably right! I have had a lot of issues, even recently, when trying to use less than or more than with variables that can result in negative values. Just one example:

A warning has to pop up if the elapsed time is more than 5 minutes. If you do some calculations that can result in a negative value lower than -5 minutes, the warning will pop up. There I am very sure, because I had to create a similar work flow recently in CP9. 

Maybe Rod can explain? I am not a programmer, all my knowledge about Captivate is based purely on experience with (lot of) advanced/shared actions. That resulted in me believing that Captivate doesn't know the difference (for literal) between a number or a string. It even happened that when you add two numbers, that they were concatenated instead of having the sum calculated. For that situation I know that you mostly can force the calculation by giving a default numeric value to the variables (like 0) when defining them. But I never could have a comparison with a negative value work as expected till today. It always looked like Captivate ignored the negative sign totally.

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
Explorer ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

I don't doubt you encountered some situation that behaved strangely and made it seem that there's a problem comparing negative values.  I will be on the lookout for strange behavior.

However, I did a further test for fun:  I created a user variable called minusEight and gave it the value -8.  I then created a conditional action that assigned a messageVar the value "is less than" under the condition:

    IF -6  is less than  minusEight

else it was assigned "is not less than".  Then I hooked up a button to run the Action and a text box to show the result. 

If it were a text comparison, -6 WOULD be less than -8 ALPHABETICALLY. 

If it were a numeric comparison, -6 would NOT be less than -8. 

Result:  -6 was not less than minusEight. 

Then I replaced minusEight with a literal -8 and ran it again:  same result.

So these tests make it appear that it does convert "numerical text" values to numbers before comparing them.

Of course, there may be cases where it doesn't work as it should.........

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 ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

Did you try it the other way? I mean: to put the literal to the right and the variable to the left of the operator?

At least, for me, what I explained was not working at all. I compared the result of a calculation (var)  with a numerical value in the literal to the right, and it wouldn't function at all. I gave only one example (recent) but I encountered that situation quite a lot of times.

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
Explorer ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

I just tried it the other way.  It behaved the same:  as if the comparison were numerical rather than alphabetical. 

Then, I changed the literal being compared to -999:

     IF  minusEight  is less than  -999

           say "is less than"

     ELSE

           say "is not less than"

Result:  "is not less than"

So again it worked OK.  Had it been an alphabetic comparison, -8 would be less than -999, since 8 comes before 9 "alphabetically".

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 ,
Apr 21, 2016 Apr 21, 2016

Copy link to clipboard

Copied

LATEST

In that case, why was it not working for me in more complicated scenarios.

I try to avoid working with negative numbers whenever possible for the

reasons I mentioned.

Thanks for testing!

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