Facility Control

 View Only
  • 1.  Creating Parameters through Scripting

    Posted 01-23-2016 15:21

    Hello,

    I'm working on a dashboard panel for baseball scoring. I want to add an inning-by-inning score; however, I'd like to create the parameters as the game progresses instead of adding them to the parameter list. My thought process behind doing it as the game progresses is 1) if a game goes into extras, it'll automatically add the innings and b) if the bottom of an inning isn't played (either due to weather or the home team leading in the top of the 9th), I want it to be a string ("X") instead of an integer ("0").

    I've tried going through the documentation and I've attempted (all separately):

    var home_innScore_1 = params.createParam(INT32);

    myOID = params.toOid('home_innScore_1');

    params.createCopy('game_innScore_template_num', 'home_innScore_');

    The only one I've had some success for, is params.createCopy('game_innScore_template_num', 'home_innScore_');. However, I cannot get it to work when I put it into an if statement that determines if it's the top or the bottom of the inning:

    ogscript.debug('BUTTON PRESSED');
    var innStatus = params.getValue('game_inn_status_full', 0)

    // Checks if it's the top of the inning
    if (innStatus == 1)
    {
    params.createCopy('game_innScore_template_num', 'away_innScore_');
    ogscript.debug('BOT GOOD');
    }
    // Checks if it's the bot of the inning
    else if (innStatus == 3)
    {
    params.createCopy('game_innScore_template_num', 'home_innScore_');
    ogscript.debug('BOT GOOD');
    }

    I can see the ogScript debug message appear, but none of the parameters are created. I would appreciate any help that could help me figure out why this isn't working, what is the best way to add the inning number to the OID and then how to delete all of them once a game is complete.

    Thank you for your help.

    Rob Rowe



  • 2.  RE: Creating Parameters through Scripting

    Posted 02-09-2016 14:23
    Hey all,

    I've really hit a wall and can't seem to figure out what I'm doing wrong here - any help is appreciated.

    Rob
    #DashBoard


  • 3.  RE: Creating Parameters through Scripting

    Posted 04-09-2016 08:26
    We are looking to do this too if anyone can help. We would like to create a set of parameters, based on a for loop or something...
    #DashBoard


  • 4.  RE: Creating Parameters through Scripting

    Posted 04-11-2016 15:41

    Does it have to be a parameter, or would a global Object with key / value pairs do the job?

    Add an API tag and put this code into it:

    var myParams = new Object();

    then wherever you need to add a new key / value pair:
    myParams.anything = 'hello';

    Or, to use a variable as a key:

    var myKey = 'test';
    myParams[myKey] = 'hello world';

    ogscript.debug(myParams[myKey]);
    ogscript.debug(myParams.test); //same result as line above

    It isn't a parameter, but might be a solution?


    #DashBoard


  • 5.  RE: Creating Parameters through Scripting

    Posted 04-11-2016 19:38

    While there are ways to create parameters programmatically, I wonder if your exact scenario might be better resolved by making your score an integer array. Then you could add a new element for each inning.

    params.getParam('score', 0).setAllValues([0]); //Reset for first inning
    params.getParam('score', 0).setValueAt([inning], [the score for the inning]);

    If you want to show an "X" instead of a number at various times, then I would just make the parameter a STRING_ARRAY and, if you need to add to it use parseInt([string value]) to make it a number temporarily.


    #DashBoard


  • 6.  RE: Creating Parameters through Scripting

    Posted 04-11-2016 19:47

    If you did want to create a parameter anyhow, here is an example of how that works:

    var paramObject ={
    "oid": "new_param",
    "name": "New Parameter",
    "readonly": false,
    "type": "STRING",
    "widget": "label",
    "value": "Hello World"
    };

    var newParam = params.createParam(paramObject);
    ogscript.debug(newParam.getValue());

    #DashBoard


  • 7.  RE: Creating Parameters through Scripting

    Posted 08-10-2017 08:43

    Hi. Regarding creating parameters by scripting:
    We would like to create parameters through scripting but have problems setting constraints on creation of the parameter.
    The reason for this is the amount of parameters available each day is totally random (gambling odds/ different games each day), ranging from 10 - 300 and we would not like to clutter our code unnecessarily.

    • What is the right syntax for setting an integer choice constraint in the paramObject? (see below)
    • And another thing, is it possible to flush/delete parameters by scripting (by the end of the day) as well? If so, how?
    var paramObject ={
    "oid": "TESTPARAM",
    "name": "This is the test parameter",
    "readonly": false,
    "type": "INT16",
    "widget": "toggle",
    "value": "1",
    "constrainttype" : "INT_CHOICE"
    };

    // Create the new parameter
    var newParam = params.createParam(paramObject);
    ogscript.debug(newParam.getValue());

    // Create the new constraint array
    var cArray = new Array();
    cArray.push({key:0,value:'Off'});
    cArray.push({key:1,value:'On'});
    ogscript.debug(cArray);

    // Apply the new choice constraints from the constraint array
    var choiceConstraint = params.createIntChoiceConstraint(cArray);
    params.replaceConstraint('TESTPARAM', choiceConstraint); // NOT WORKING ????

    #DashBoard


  • 8.  RE: Creating Parameters through Scripting

    Posted 08-10-2017 12:57

    Your constraint definition in the parameter is not valid so it is being defaulted to an unconstrained parameter. params.replaceConstraint only works if the parameter types match so the 'unconstrained' param cannot be replaced with the 'choice' param:

    This will fix your parameter definition:

    var paramObject ={
       "oid": "TESTPARAM",
       "name": "This is the test parameter",
       "readonly": false,
       "type": "INT16",
       "widget": "toggle",
       "value": "1",
       "constraint": 
       {
          "type": "INT_CHOICE",
          "choices": [{
             "name": "OFF",
             "value": 0
             }, {
             "name": "ON",
             "value": 1
          }]
       }
    };
    
    // Create the new parameter
    var newParam = params.createParam(paramObject);
    
    /*
    
    NOTE: YOU DO NOT NEED THIS PART NOW
    
    ogscript.debug(newParam.getValue());
    
    // Create the new constraint array
    var cArray = new Array();
    cArray.push({key:0,value:'Off'});
    cArray.push({key:1,value:'On'});
    ogscript.debug(cArray);
    
    // Apply the new choice constraints from the constraint array
    var choiceConstraint = params.createIntChoiceConstraint(cArray);
    params.replaceConstraint('TESTPARAM', choiceConstraint);*/

    #DashBoard


  • 9.  RE: Creating Parameters through Scripting

    Posted 08-10-2017 13:43
    Great, thanks. I didn't know we could do it when instantiating the parameter.
    #DashBoard