Facility Control

 View Only
  • 1.  Search String Parameter

    Posted 11-12-2018 14:10

    I want to use the indexOf function to search a string parameter (does it need to be an array?) to find the string position equal to the string name searched. And then use that variable to recall the position of the clip.

    Example being, if I had a clip called breaking_news and it was the 7th item listed var i would = 7 after the search and then the task would recall that number from var i.

    I know I'm not putting in something correctly and apologizes for my terrible coding.

    <param access="1" constrainttype="STRING_CHOICE" maxlength="0" name="List" oid="0x3" type="STRING" value="a" widget="default">

    var i = params.getIndexof(List, 0)

    <task tasktype="rosstalk">rosstalk.sendMessage('100.121. 85.37', 9993, 'goto: clip id: i');</task>


  • 2.  RE: Search String Parameter

    Posted 11-13-2018 20:13

    indexOf only works on String objects. There is no 'indexOf' in the params object.

    In the code above, it looks like you may get better use out of using an INT parameter with an INT_CHOICE constraint. Then, the value of the parameter would be the same as the index of the selected item.

    <abs contexttype="opengear" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="Clip IDs" oid="Clip_IDs" precision="0" type="INT32" value="3" widget="combo">
                <constraint key="0">Clip 1</constraint>
                <constraint key="1">Clip 2</constraint>
                <constraint key="2">Clip 3</constraint>
                <constraint key="3">Clip 4</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="48" left="35" oid="Clip_IDs" top="41" width="318"/>
       <button buttontype="push" height="56" left="357" name="Go" top="39" width="99">
          <task tasktype="ogscript">ogscript.debug('SELECTED INDEX: '  + params.getValue('Clip_IDs', 0));</task>
       </button>
    </abs>

    Otherwise, you could write a utility function to get the constraint (list of choices) and find out which one is selected:

    <abs contexttype="opengear" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="STRING_CHOICE" maxlength="-1" name="Clip IDs" oid="Clip_IDs" type="STRING" value="Clip 1" widget="combo">
                <constraint>Clip 1</constraint>
                <constraint>Clip 2</constraint>
                <constraint>Clip 3</constraint>
                <constraint>Clip 4</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="48" left="35" oid="Clip_IDs" top="41" width="318"/>
       <button buttontype="push" height="56" left="357" name="Go" top="39" width="99">
          <task tasktype="ogscript">function indexOfSelection(oid)
    {
       var param = params.getParam(oid, 0);
       var choices = param.getConstraint().getChoices();
       var value = param.getValue();
       for (var i = 0; i &lt; choices.length; i++)
       {
          if (value == choices[i])
          {
             return i;
          }
       }
    
       return -1;
    }
    ogscript.debug('SELECTED INDEX: '  + indexOfSelection('Clip_IDs'));</task>
       </button>
    </abs>

     


    #DashBoard


  • 3.  RE: Search String Parameter

    Posted 01-14-2019 15:08

    Sorry for the delayed response, I've been trying to get a better understanding of how this works. I've gotten the list to populate and I can search the constraints, but what I think I need to search is the constraint key. Here is a (much) shorter version of the parameter list:

    <param access="1" constrainttype="INT_CHOICE" name="1 Clip List" oid="0x2" precision="0" type="INT32" value="50" widget="combo">
    <constraint key="0">01_SetHFin Desk</constraint>
    <constraint key="1">02_SetHFin BN Desk</constraint>
    <constraint key="2">03_SetHFin BN Today</constraint>
    <constraint key="3">04_SetHFin Today</constraint>
    <constraint key="4">05_SetHFin News Now</constraint>
    </param>

    The problem I run into is we have multiple sources that would have the same items but in different places. I want to compare the constraint key to a predetermined value such as 04_SetHFin Today and then set the parameter to that constraint value when found. Is there a way to query that?


    #DashBoard