Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Dienstag, 10. November 2009, 19:28

Help with if condition

Hi,



I have defined my own variable in that style:



Quellcode

1
 <hoteldata name="hotel1" hname="aName" hurl="aUrl" />




As I want to change them from outside I want to do something if the variable exist or not.



Quellcode

1
2
 if(get(hoteldata[hotel1].hname) != null ,additem(get(hoteldata[hotel1].hname), openurl(get(hoteldata[hotel1].hurl),_blank)) 
);




What I want to is to add that item if the variable exists. If it doenst exist I do not want to do that.

If I delete the variable the item is still added showing "null" even if I did a check that I do want to show it if it is not null.



Any ideas what I've done wrong?



Regards

2

Mittwoch, 11. November 2009, 09:22

Hi malojo,

I have tried your code and the problem seems to be that the if action is not resolving correctly the null value... trace(hoteldata[hotel1].hname
) returns null... get(hoteldata[hotel1].hname) returns null... but if(hoteldata[hotel1].hname != null , ....) does not resolve correctly... it is like If() is not checking for the "null object" but check for a value... and it resolve that this value is not equal to null....(hope that the above has some sense *rolleyes* )

Perhaps that is a bug ...

So, I think you can resolve this, in setting the value to "null" and check to to the value != "null". Like this:

Quellcode

1
2
3
4
<hoteldata name="hotel1" hname="null" hurl="null" />
....
if(get(hoteldata[hotel1].hname) != "null" ,additem(get(hoteldata[hotel1].hname), openurl(get(hoteldata[hotel1].hurl),_blank)) );
....


Hope this can help.

SAlut.

3

Mittwoch, 11. November 2009, 09:56

Thanks for the hint.

It seems that there is ( besides checking for null ) another issue with the get function.



Even if I do the following



Zitat

if(get(hoteldata[hotel1].hname) == "123"

assuming that hname is 123 I get false.

If I do

Zitat

if( hoteldata[hotel1].hname != "123"

I get what I want.

4

Mittwoch, 11. November 2009, 10:08

Hi malojo,

Yes, you are right *g* ...
if(variable == "value" ,do something , else another thing)
so, if hname = "123":
if(get(hoteldata[hotel1].hname) == "123", .....)
is like:
if( 123 = "123",....)
123 is a variable (not defined in this case), so the condition is false *rolleyes* ...

SAlut.

5

Mittwoch, 11. November 2009, 10:12

Oh ehm *g* *cool* *rolleyes* *rolleyes* *whistling*

Thanks for the explanation.



Regards.

6

Mittwoch, 11. November 2009, 23:06

Zitat

if(get(hoteldata[hotel1].hname) != null ,additem(get(hoteldata[hotel1].hname), openurl(get(hoteldata[hotel1].hurl),_blank))
);
Hi,

the if() action works a bit different at the moment:
- get(var) can't be used, it automatically uses the content of a variable,
- if a variable doesn't exists, the name of the given variable is used,

e.g. when hname is set to "xyz":

Quellcode

1
if(hoteldata[hotel1].hname != null , ...)  
the if will become to:

Quellcode

1
if(xyz != null , ...) 
but when hoteldata[hotel1].hname was NOT set, the if will become finally to:

Quellcode

1
if('hoteldata[hotel1].hname' != null , ...)


I know - not ideally!
the reason for that behavior was that originally there were no quotes (') for strings,
so everything could be a either a string or a variable,
I'm still thinking about to change that...

best regards,
Klaus

7

Donnerstag, 12. November 2009, 10:11

Good to know this. Now that I do I won't have problems with it.



Thanks klaus.

8

Mittwoch, 18. November 2009, 11:37

My temp. workaround for "does the plugin/hotspot exist?" in the current scene is
eg.
if(hotspot[video].name == video, dosomething, dosomethingelse);

Seems a little bit annoying to "compair a plugins attribute against this attribute itself"
but it was the ONLY reliable way to ensure its existance -
If the plugin/hotspot was not defined before the if-condition delivers a "FALSE"-value.
You surely could use any other attribute of it instead of its name but using the name ensures to have always the right value to compare with...

Any other/better method?
best regards from www.PanAustria.com