Announcement

Collapse
No announcement yet.

Retrieving Global Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving Global Values

    Hi. A global value can be set using the following format:

    Var Int = parseInt(getInterval());
    setGlobalValue("Variable"+Int, Variable2);

    Is there a comparable format to retrieve global values based on different intervals along the lines of:

    function preMain() {
    var x=0;
    fpArray[x] = new FunctionParameter("Int", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    }

    function main(Int) {
    var Variable3 = getGlobalValue("Variable"+Int);
    }

    Thanks.
    Mike

  • #2
    Hi Mike,

    If you want to create a simple system of format rules, you can readily create one. Here is what I remember on the subject of what I have heard referred to as "true global variables" ...

    There are three commands that I use to label global variables in addition to a simple naming structure.

    getInvokerID() returns a string that is unique to the chart
    getInterval() returns a string that is unique to the intervals
    getSymbol() returns a string that is unique to the symbol

    For example, if you want to broadcast a global that represents seconds, you would just want to use the getInterval() method then add a string "seconds" for clarity. I try and enclose the string that is used as the name in parenthesis. setGlobalValue(("my name"+getInvokerID()+getInterval()), myVariable); (better yet, only create the string once and cache it by assigning to a regular global variable)

    You can also test whether another chart has already created a global variable (very handy). I do this by comparing the value returned from a getGlobalValue(string name) method to null using three equal signs. This prevents type conversion (e.g. null will equal zero or a false with two equal signs, likewise, a string "1" will equal a numerical 1 with two equal signs) which can at times be confusing, so I do this just to keep things straight. If the returned variable has been created already, it will not be null. Otherwise, it exists and does not need to be re-created.

    Let me know if this is sufficient, or we can pursue this further if you would like

    Originally posted by mikejhelms
    Hi. A global value can be set using the following format:

    Var Int = parseInt(getInterval());
    setGlobalValue("Variable"+Int, Variable2);

    Is there a comparable format to retrieve global values based on different intervals along the lines of:

    function preMain() {
    var x=0;
    fpArray[x] = new FunctionParameter("Int", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    }

    function main(Int) {
    var Variable3 = getGlobalValue("Variable"+Int);
    }

    Thanks.
    Mike

    Comment


    • #3
      Hi Mike,

      This is a followup of my last post. I enclosed an efs that demonstrates some of the techniques I described.

      Hope this helps,
      Attached Files
      Last edited by ; 03-20-2009, 09:34 AM.

      Comment


      • #4
        Wonderful layout of the options for setting and getting global values, Steve. I’m going to play with them for awhile to see if I can apply some of the concepts to my particular situation. Like others who posted in this thread I wasn’t aware of the existence of getInvokerID(). Checking back I now see it’s been around since 2003. I’m considering having a port implanted in my frontal lobe so I can simply plug in once a day and sip coffee while relevant info is downloaded keeping me current in this and other areas.

        Mike

        Comment

        Working...
        X