Facility Control

 View Only
  • 1.  using this keyword to get and set value of parameters

    Posted 09-27-2018 19:01
    Been learning some Javascript and was excited after I got a debug message to display this.value. however, i want to create some generic functions that I can use the parameters I call those functions within to get the value of that parameter and set the value of that parameter. I couldn't seem to figure this out. is there a javascript method or OGscript method that allows me to get "THIS" parameter's name?
    for instance:

    /*function that can be placed in any parameter to prevent negative values. however, this code gives me a errors.*/
    checkingNeg(this.value) {
    if (this.value < 0) {
    params.setValue(this, 0, 0);
    }
    }

    hope this makes sense, and if someone knows a better way to do this than using THIS, then that's cool too. thanks for any help. this community is awesome!


  • 2.  RE: using this keyword to get and set value of parameters

    Posted 09-27-2018 19:25

    If you are in a inside of a parameter the "this" object is the equivalent of calling params.getParam(OID, index);

    if (this.getValue() < 0)
    {
        this.setValue(0);
    }

    Though, if you are trying to enforce a range, why would you not use a range constraint on the parameter?

    James


    #DashBoard


  • 3.  RE: using this keyword to get and set value of parameters

    Posted 10-10-2018 13:02
    If you are in a inside of a parameter the "this" object is the equivalent of calling params.getParam(OID, index);

    So, you could do:
    if (this.getValue() < 0)
    {
    this.setValue(0);
    }



    Though, if you are trying to enforce a range, why would you not use a range constraint on the parameter?

    James



    yes. i am trying to enforce a range. some of these parameter are the calculation of other entries. NaN keeps showing up because by default a lot of the values are 0, and when calculating percentages, 0 divided by 0 is NaN. 0% is still a valid statistic to put live on air but I'd like to eliminate the NaN. will the range constraint still help? how do i do that?
    #DashBoard


  • 4.  RE: using this keyword to get and set value of parameters

    Posted 10-10-2018 14:36

    For what you're describing, a range won't change what you need to do. The ranges tell the UI to stay within your min/max but that won't help your percent (and they can also still be set outside of their range via ogScript).

    You may want to do your negative check before the division to avoid the NaN:

    var percent = 0;
    var val = this.getValue();
    if (val > 0)
    {
        percent = YOUR_OTHER_VALUE / val * 100;
    }

    #DashBoard