Help with if condition

  • Hi,


    I have defined my own variable in that style:


    Code
    <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.


    Code
    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

  • 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:

    Code
    <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.

  • 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.

  • 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.

  • 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":

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

    the if will become to:

    Code
    if(xyz != null , ...)

    but when hoteldata[hotel1].hname was NOT set, the if will become finally to:

    Code
    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

  • 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?

Jetzt mitmachen!

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