if( testvariable conditions fail to evaluate for string variables etc

  • krpano.call("testme(c3,false);");
    undefined
    krpano.call("testme(c3,fals);");
    undefined
    krpano.call("testme(c3,5);");


    INFO: false not===null
    INFO: false not==null
    INFO: false not

    INFO: fals ===null
    INFO: fals not==null
    INFO: fals not

    INFO: 5 ' exists'
    INFO: 5 ===null
    INFO: 5 not==null

    Problems are:

    Everything === null except for boolean values

    if(var,... doesn't work for non numeric values

    errata
    z === null
    "z=" not ===null

  • Hi Sacha,

    I think I'm seeing the same "null" behavior as perhaps you've noted.

    If I go to a tour on open it loads and then switched to a "null" ending URL. If I use the browser method to go back, the tour works as intended without any more "null" links.

    And I'm seeing this on old tours, built long before 1.117 and never updated, new behavior from an old tour. So I'm guessing something somewhere has changed but perhaps not in KRPano?

    This one seems like it's going be a bit hard to figure out where this issue is.

    Robert

  • I'm not sure what you mean, but I think I've always had difficulties with my ifs. I just keep on trying different things until it worked. Usually when I use strings I check against a string and that's fine.
    Instead of relying on null, you can use false or true and make sure your arguments are set accordingly or use other arguments to set the state. In any case, I think this situation will be resolved when Klaus has a spare moment shortly.

  • Well maybe it's a different thing.

    When I load a tour, some of them, it loads, but then switches to a "null" link. This is simply with using the default VTour droplet results.

    Perhaps it's local, but I just had my first client note this.

    So?

  • Hi,

    Everything === null except for boolean values

    The if() action is working as it should in your case.

    Here a slightly re-arranged version of your 'testme' action with more detailed output - this should better explain how the if action is working:

    Code
    <action name="testme">
        if   (%2,          trace(%2 ,' - exists as variable or has a value that is not false'); );
        ifnot(%2,          trace(%2 ,' - does not exists as variable or the value of it is false'); );
        if   (%2 === null, trace(%2 ,' - is not a variable'); );
        ifnot(%2 === null, trace(%2 ,' - is a variable'); );
        if   (%2 == null,  trace(%2 ,' - is null'); );
        ifnot(%2 == null,  trace(%2 ,' - is not the same as null'); );
    </action>

    When calling:

    Code
    testme(c3,false);
    testme(c3,fals);
    testme(c3,5);

    this will be the result:

    Code
    INFO: false - does not exists as variable or the value of it is false
    INFO: false - is a variable
    INFO: false - is not the same as null
    INFO: fals - does not exists as variable or the value of it is false
    INFO: fals - is not a variable
    INFO: fals - is not the same as null
    INFO: 5 - exists as variable or has a value that is not false
    INFO: 5 - is not a variable
    INFO: 5 - is not the same as null


    if(var,... doesn't work for non numeric values

    There is basically a two-step check here - first the if() action checks if there exists a variable named 'var' - and if one exists, it will check the value of it.

    This is done due a limitation of the current action system - the action system itself is 'typeless' - that means there is no difference between a string/text or a variable name. The quote characters are only used to 'quote' a given parameter from parsing other key-characters (like comma or brackets), but don't have any influence to the variable/value type itself.

    To check directly if a variable exists or not, the '===' or '!==' operators need to be used (btw - true and false are internally variables, so testing if they are variables will succeed).


    There is currently also another limitation related to checking if a variable exists or has the value null - internally the get() action, which gets the value of a variable always returns either the value of the variable or null - so it's currently not possible to differ between a not-defined-variable and a variable that has null as value, because in both cases null will be returned.

    But this one limitation will be fixed in the next release - then the get() action will return 'undefined' for a not defined variable and this will allow the if() action to differ between not defined variables and variables with the value null.

    I have made a special if() test case here for testing this and other if() situations:
    https://krpano.com/krpano.html?xm…ts/if-tests.xml
    xml:
    https://krpano.com/examples/actiontests/if-tests.xml

    In the current 1.17 version 3 tests will fail, but in the next 1.18 version all tests will pass.


    Btw - I'm of course also considering a more advanced script system without such limitations, but that can't be made to be compatible to the current system, so this is more something for a future krpano '2.0' version.


    When I load a tour, some of them, it loads, but then switches to a "null" link. This is simply with using the default VTour droplet results.

    Sorry, but I have no idea what you mean here and I doubt that this would be related to the if() action...

    Best regards,
    Klaus

Participate now!

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