Sie sind nicht angemeldet.

360boy

Fortgeschrittener

  • »360boy« ist der Autor dieses Themas

Beiträge: 249

Wohnort: Mexico City

Beruf: Virtual tours, Krpano coding, Graphic Design, Photographer, Panographer

  • Nachricht senden

1

Mittwoch, 15. August 2018, 15:42

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*

2

Mittwoch, 15. August 2018, 22:35

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:

Quellcode

1
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

360boy

Fortgeschrittener

  • »360boy« ist der Autor dieses Themas

Beiträge: 249

Wohnort: Mexico City

Beruf: Virtual tours, Krpano coding, Graphic Design, Photographer, Panographer

  • Nachricht senden

3

Dienstag, 25. September 2018, 17:19

Thanks Klaus,
I find this method useful on some cases but won't work to distinguish a string of a boolean. Anyway, thanks for you help and I'll certainly use this method when it's appliable.
Best
Luis *thumbup*

4

Sonntag, 30. September 2018, 23:43

Luis,
Try

Quellcode

1
2
3
4
5
6
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