Facility Control

 View Only
  • 1.  Object creation

    Posted 05-25-2022 09:39
    Is the only way to create a global object by using the ogscript put/get object method?  We cannot use a standard JavaScript object, ie create an array of JavaScript objects?

    ------------------------------
    Matt Rasmussen
    FinePoint Technology
    ------------------------------


  • 2.  RE: Object creation

    Ross Staff
    Posted 05-25-2022 13:32
    If you define variables in an <api/> block at the top-level scope of your panel, you can get or set them in other scripts in your panel if you don't wish to use ogscript.putObject/getObject.

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false">
       <meta>
          <api>var name = "James";</api>
       </meta>
       <button buttontype="push" height="100" left="40" name="Set Name" top="60" width="220">
          <task tasktype="ogscript">name = "Jack";</task>
       </button>
       <button buttontype="push" height="100" left="40" name="Debug Name" top="180" width="220">
          <task tasktype="ogscript">ogscript.debug(name);</task>
       </button>
    </abs>
    ​



    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: Object creation

    Posted 05-25-2022 13:51
    I believe I tried that, but the variables are setup within a function, is that limiting me in scope?  The button press calls the function located in <API> which does call the function and the function runs but those values don't seem to be 'gettable' anywhere else.

    Also, am I correct that I cannot script JavaScript like a class constructor to build an array of objects?  I will have to use the XML object and/or setup every variable in <API>?

    Thanks James!

    ------------------------------
    Matt Rasmussen
    FinePoint Technology
    ------------------------------



  • 4.  RE: Object creation

    Ross Staff
    Posted 05-25-2022 14:08
    Correct - variables declared inside of functions are scoped to that function or any sub-functions.

    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------