Topic
8 replies Latest Post - ‏2013-10-29T18:38:30Z by GregM_dxler
bandchef
bandchef
17 Posts
ACCEPTED ANSWER

Pinned topic Link == true? Possible?

‏2013-10-25T12:53:42Z |

It is possible to prompt with a if-statement if a link in a object is existing? I mean:

for gobj_CurrentObject in gmod_CurrentModule do

{

for lnk_OutLink in gobj_CurrentObject -> "*" do

{

  if(exists(outgoingLink) == true){}

}

}

 

Is there a function among the DXL Statements which satisfies my wish?

  • GregM_dxler
    GregM_dxler
    120 Posts
    ACCEPTED ANSWER

    Re: Link == true? Possible?

    ‏2013-10-25T13:09:46Z  in response to bandchef

    Hello,

    If your inside the for loop that goes through all outlinks, then you must have an outlink and you don't need the if statement.  If there is no outlinks, then the for loop is skipped.

    Greg

  • bandchef
    bandchef
    17 Posts
    ACCEPTED ANSWER

    Re: Link == true? Possible?

    ‏2013-10-28T13:49:59Z  in response to bandchef

    Thank you for your answer!

    I have written now this code:

     

    for gobj_CurrentObject in gmod_CurrentModule do

    {

    for lnk_OutLink in gobj_CurrentObject -> "*" do

    {

    //Debug

    print numLinks gobj_CurrentObject."Object Text" "\n"

    gobj_CurrentObject."p_Link_Feature_existing""" == "True"

    }

    }

     

    The thing is, that the debug statement appears in the interaction window of doors. But the line "gobj_CurrentObject."p_Link_Feature_existing""" == "True"" takes no effect. The Attribute p_Link_Feature_existing has "true" or "false" to choose. I have thought, if i make a left association the script can set the displayed value in doors...

     

     

    I'm so sorry. I have Chosen the inocorrect Statement. This is the correct Statement:

    gobj_CurrentObject."p_Link_Feature_existing" = "True"

    Updated on 2013-10-28T14:04:15Z at 2013-10-28T14:04:15Z by bandchef
    • pommCannelle
      pommCannelle
      31 Posts
      ACCEPTED ANSWER

      Re: Link == true? Possible?

      ‏2013-10-28T14:39:58Z  in response to bandchef

      ( Hmmm ... You should try something like this ...

      bool hasInLink( Object o, string linkModName ) {
          Link l
          for l in o<-linkModName do return true
          return false
      }
      bool hasInLink( Object o ) { return hasInLink( o, "*" ) }
      bool hasOutLink( Object o, string linkModName ) {
          Link l
          for l in o->linkModName do return true
          return false
      }
      bool hasOutLink( Object o ) { return hasOutLink( o, "*" ) }
      bool hasLink ( Object o ) { return ( (hasOutLink o) || (hasInLink o) ) }
      Object o

      for o in current Module do { o."p_link_feature_existing" = hasLink o }

      Feel free to post your code if you are in trouble ;) )

    • GregM_dxler
      GregM_dxler
      120 Posts
      ACCEPTED ANSWER

      Re: Link == true? Possible?

      ‏2013-10-28T16:00:56Z  in response to bandchef

      Hello,

      If the attribute p_Link_Feature_existing is a boolean, then your assignment statement should not have "True" but just true without the double quotes.  The double quotes would be used if the attribute is a string.

      This error has nothing to do with the loop.

      Greg

    • llandale
      llandale
      2809 Posts
      ACCEPTED ANSWER

      Re: Link == true? Possible?

      ‏2013-10-28T18:51:19Z  in response to bandchef
      • gobj_CurrentObject."p_Link_Feature_existing""" == "True"

      With "==" that is not an assignment statement, it is a comparison.  It calculates to either true or false but does nothing besides that, and for some reason DXL doesn't complain.  That like talking to somebody and saying "The Car".  Use a single equal sign for assignment; get rid of double double quotes.  If the attr is really a boolean, do this:

      • gobj_CurrentObject."p_Link_Feature_existing" = true

      Actually I think what you want is the following.  Lets create a boolean Attr-DXL that is "true" if the object has an outlink otherwise "false".  This way the attr always has the correct information and you don't need to run an on-demand script to update the values.

      • bool HasLink = false
      • Link lnk
      • for lnk in obj-> "*" do

      •      // if (I don't care about THIS link) then continue
        //Debug
      •      print "Has Link\t" identifier(obj) "\n"
             HasLink =  true
      •      break    // no reason to keep looking
      • }
      • obj.attrDXLName = HasLink

      Merge in pommCannelle's good clean advise: do well defiined chores in well defined functions.

      Now if your target attr is not "boolean" but is enumerated with "true" and "false" or "True" and "False" then your assignment would be a string. 

      -Louie

      Digressing:  If "False" is the first enumeration and "True" is second, turns out the boolean assignment will still work.

      • GregM_dxler
        GregM_dxler
        120 Posts
        ACCEPTED ANSWER

        Re: Link == true? Possible?

        ‏2013-10-28T20:24:53Z  in response to llandale

        Owwww, my eyes can't see the fine print!

        • llandale
          llandale
          2809 Posts
          ACCEPTED ANSWER

          Re: Link == true? Possible?

          ‏2013-10-29T18:20:16Z  in response to GregM_dxler

          Don't know what I did wrong; cannot preview.  Any ideas?

          • GregM_dxler
            GregM_dxler
            120 Posts
            ACCEPTED ANSWER

            Re: Link == true? Possible?

            ‏2013-10-29T18:38:30Z  in response to llandale

            Must be a forum "enhancement".

            bandchef had already acknowledged that the "==" should have been an assignment "=" in his (?) fine print.  The text below the square bullets is too small to read.  Not sure if that was because you copied his text to your reply, the font size got even smaller then what he had (which is way too small).  It seems to be below the resolution of my monitor now.

            Greg