Skip to main content
Inspiring
April 20, 2016
Answered

Conditional Action Numeric Comparison Problem

  • April 20, 2016
  • 2 replies
  • 1400 views

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?

This topic has been closed for replies.
Correct answer david_slayton

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.

2 replies

david_slaytonAuthorCorrect answer
Inspiring
April 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 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.

Lilybiri
Legend
April 21, 2016

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

Inspiring
April 21, 2016

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

Lilybiri
Legend
April 20, 2016

What do you really want to check, please?

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

Inspiring
April 20, 2016

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.

Lilybiri
Legend
April 20, 2016

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.