is comparing variables bug?

  • Hello, everyone!

    I need your help to resolve my issue! I'm writing code which should invoke showtext. My variable get the value of any character string, empty string and value 0. Depending on the case i need to check if variable is 0 or empty string like this. Additional information may be that the variable is taken from the krpanoteamplate. Pice of code from template.xml:


    <hotspot name="{{Id}}" type="image" style="style" ath="{{Longitude}}" atv="{{invertLatitude}}"
    name="{{name}}" />

    and also i have action which invoke external plugin "showtext" depending on variable if doesn't empty, like this:

    if(name !== ' ', showtext(get(name), warpNameStyle, screenX, screenY););



    it works partly! but if variable 'name' has 0, it's also will ommited!!



    I came to conclusion that 0 and ' ' is the same type??


    I made quick test:

    set(a, "");
    set(b, 0);

    if(a == b, trace('TRUE'));
    if(a === b, trace('TRUE'));

    and i got TRUE for two cases!!!!!

    My question is. How can i invoke showtext while variable has 0? And how compares these variables a,b?

    Greetings!!

    Edited once, last by rejentt (December 11, 2017 at 3:01 PM).

  • maybe you should use :

    if(name !== null, showtext(get(name), warpNameStyle, screenX, screenY););

    but...

    Code
    set(a, "");
    set(b, 0);
    if(a == b, trace('TRUE'), trace('FALSE'));
    if(a === b, trace('TRUE'), trace('FALSE'));

    this should be FALSE for both cases, at least for the second!
    ... hmmm klaus?


    even if you set(a, " "); you get both true.. *confused*

  • Hi,

    that's how Javascript is working: (krpano is based on Javascript):
    https://developer.mozilla.org/en-US/docs/Web…_equality_using

    But different to Javascript the '==' and '===' are doing the comparison operation, the '===' is additionally only checking if the variable exists. That means the '==' and '===' in krpano should work equality to the '==' in Javascript.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!