Finding out the kind of attribute (Number, boolean, string)

  • Hello there,
    For a current project I need to distinguish internally at Krpano the categories of attributes. I'm working currently with automatic gallery scenes creation, it's based in a single attribute to categorize it but if user sets it's value wrong, let's say it should be category="aerial" but instead a number was used it screws all the automation. I need to set some conditionals to distinguish if a non string value was assigned and to report/correct the issue.
    Is there a way to find out the kind of category of an attribute for this purpose?
    Thanks!
    Luis *thumbup*

  • Hi,

    the exact type doesn't need to be defined for krpano, the action or the operation where a variable will be used defines the type in the most cases...

    E.g. even when a variable is a string like "123" it will be possible to use it in a mathematical calculation (similar to JS).

    For checking if a variable is a number you could try this:

    Code
    if(var * 1 == var, trace(is a number), trace(is not a number));


    The multiplication forces a conversion to a number, and for non-numbers this will fail. So when the value is still the same after the multiplication, it is a number.

    Best regards,
    Klaus

  • Luis,
    Try

    Code
    calc(result, !my_input ?  'Empty input' : (my_input != aerial ?  'Wrong category' : true  ));
    if(result == true, 
        //use my_input as correct;
    '
      warning('Wrong input ', my_input, ' due ', result);
    );


    Without testing. The Klaus' test for number is very useful.

    Pavel

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!