You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

360boy

Intermediate

  • "360boy" started this thread

Posts: 221

Location: Mexico City

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

  • Send private message

1

Wednesday, August 15th 2018, 3:42pm

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

Wednesday, August 15th 2018, 10:35pm

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:

Source code

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

Intermediate

  • "360boy" started this thread

Posts: 221

Location: Mexico City

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

  • Send private message

3

Tuesday, September 25th 2018, 5:19pm

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

Sunday, September 30th 2018, 11:43pm

Luis,
Try

Source code

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