Forum Discussion

4m4d3u5's avatar
4m4d3u5
Contributor
5 years ago
Solved

Exists property

I am trying to use the Exists property in javascript. I have an object that I would like to test to see if its still up on the screen or not. I write a loop that says 

 

while( testObject.Exists){

   wait(1)

}

 

Exept when the object is no longer on the screen it says it can't find the object. I get why it can't find the object because it doesn't exist on the screen. How can I test to see if an object is no longer on the screen and how is the Exists property suppose to work?

  • I wouldn't use WaitProperty.  WaitProperty is a method assigned to an object.  So, when an object does not exist, calling that method will cause an error.

    And that's the thing about the "Exists" property.  You can't call the "Exists" property of an object that does not exist.  If the object does not exist, it has no properties at all.

    So...  if you want to see if an item is on screen, you would use WaitChild or WaitAliasChild or something like that from the parent object.

    Let's say, for example, we have the following.

     

    Aliases.MyApp

     

    And after performing some sort of function I want to see if a form in that application exists, normally indicated by

     

    Aliases.MyApp.MyForm

     

    If it's a simple if-then, I'd do the following in JavaScript

     

    if (Aliases.MyApp.WaitAliasChild('MyForm', 3000).Exists) {
        Log.Message('The form exists')
    }
    else {
        Log.Message('The form does not exist')
    }

    This code will wait up to a maximum of 3 seconds for the object to exist.  If it returns within 3 seconds, WaitAliasChild returns the actual object and Exists is true.  If the 3 second limit is exceeded, WaitAliasChild returns a "stub" object with ONLY the Exist property set to false

     

     

5 Replies

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      I wouldn't use WaitProperty.  WaitProperty is a method assigned to an object.  So, when an object does not exist, calling that method will cause an error.

      And that's the thing about the "Exists" property.  You can't call the "Exists" property of an object that does not exist.  If the object does not exist, it has no properties at all.

      So...  if you want to see if an item is on screen, you would use WaitChild or WaitAliasChild or something like that from the parent object.

      Let's say, for example, we have the following.

       

      Aliases.MyApp

       

      And after performing some sort of function I want to see if a form in that application exists, normally indicated by

       

      Aliases.MyApp.MyForm

       

      If it's a simple if-then, I'd do the following in JavaScript

       

      if (Aliases.MyApp.WaitAliasChild('MyForm', 3000).Exists) {
          Log.Message('The form exists')
      }
      else {
          Log.Message('The form does not exist')
      }

      This code will wait up to a maximum of 3 seconds for the object to exist.  If it returns within 3 seconds, WaitAliasChild returns the actual object and Exists is true.  If the 3 second limit is exceeded, WaitAliasChild returns a "stub" object with ONLY the Exist property set to false

       

       

      • 4m4d3u5's avatar
        4m4d3u5
        Contributor

        Yeah, that does exactly what I want. Thanks.