Sie sind nicht angemeldet.

1

Montag, 11. Dezember 2017, 14:26

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!!

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »rejentt« (11. Dezember 2017, 15:01)


2

Montag, 11. Dezember 2017, 16:09

maybe you should use :

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

but...

Quellcode

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

3

Dienstag, 12. Dezember 2017, 17:49

Hi,

that's how Javascript is working: (krpano is based on Javascript):
https://developer.mozilla.org/en-US/docs…_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

Ähnliche Themen