Facility Control

 View Only
  • 1.  Public Variables

    Posted 10-15-2018 16:08

    Hi,

    perhaps this is a simple question but I didn't find the solution.

    I use this script to declare my variables:

    <lookup id="globVars">
    <entry key="vars">
    var teamA="myTeam";
    var teamB="yourTeam";
    var
    </entry>
    </lookup>

    And what I want to do is when I click on my button I would like my variables update.
    So here is my script.

    <button buttontype="push" height="100" id="btn1l" left="1050" name="UPDATE VARS" style="look:flat;fg#FFFF00;" top="90" width="200">
    <task tasktype="ogscript">/
    %const['globVars']['vars']%;
    teamA="TEAM A";
    teamB="TEAM B";
    ogscript.debug(teamA);
    ogscript.debug(teamB);
    </task>
    </button>

    But debug always return "myTeam" and "yourTeam" and not "TEAM A" and "TEAM B".

    How can I proceed please ?

    Thanks



  • 2.  RE: Public Variables

    Posted 10-15-2018 19:06

    When you use %const['lookup_id']['key']% it is the equivalent of writing that exact string of text in your script. In this case, the script in the button is throwing an exception but that may be a copy/paste issue. If I type:

    <lookup id="globVars">
          <entry key="vars">var teamA="myTeam";
    var teamB="yourTeam";</entry>
       </lookup>

    (remove the extra "var" at the end)

    and remove the "/" at the start of:

    <button buttontype="push" height="100" id="btn1l" left="1050" name="UPDATE VARS" style="look:flat;fg#FFFF00;" top="90" width="200">
          <task tasktype="ogscript">%const['globVars']['vars']%;
    teamA="TEAM A";
    teamB="TEAM B";
    ogscript.debug(teamA);
    ogscript.debug(teamB);</task>
       </button>

    I do get "TEAM A" and "TEAM B" printed.

    That said, I strongly-recommend you reconsider your approach here. Using look-ups to store blocks of script was a common approach before the tag was created. Now that it exists, you are better-off declaring your common code and variables in one of those tags and working with them directly.

    <api immediate="true" name="Global Variables">var teamA="myTeam";
    var teamB="yourTeam";</api>
    <button buttontype="push" height="100" id="btn1l" left="1050" name="UPDATE VARS" style="look:flat;fg#FFFF00;" top="90" width="200">
          <task tasktype="ogscript">teamA="TEAM A";
    teamB="TEAM B";
    ogscript.debug(teamA);
    ogscript.debug(teamB);</task>
       </button> 

    #DashBoard


  • 3.  RE: Public Variables

    Posted 10-16-2018 09:56
    Sorry James, I write my script directly in the post and I make mistake.
    But you understood what I try to do.
    So now I go to change my approach to declare variables, and use tag for this.
    I try it and it works good.
    Thanks a lot.
    #DashBoard