Announcement

Collapse
No announcement yet.

Change variable value with chart button

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

  • Change variable value with chart button

    Hi:

    I'm trying to change the value of a variable ("Contracts") by left button clicking on the text displayed on the chart, but I can't seem to get it to work with the following code. Does anyone have a suggestion?

    var Contracts = 1;

    function ContractSwitch1(nButtonPressed)
    {

    Contracts = 1;

    ContractsButton1();
    }

    function ContractsButton1()
    {
    if (Contracts == 1)
    {
    drawTextAbsolute(14, 14, " " + 1 + "@URL=EFS:ContractSwitch1" + " ", Color.black, Color.lime, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB1");

    drawTextAbsolute(17, 14, " " + 2 + "@URL=EFS:ContractSwitch2" + " ", Color.black, Color.white, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB2");
    }
    }

    function ContractSwitch2(nButtonPressed)
    {

    Contracts = 2;

    ContractsButton2();
    }

    function ContractsButton2()
    {
    if (Contracts == 2)
    {
    drawTextAbsolute(17, 14, " " + 2 + "@URL=EFS:ContractSwitch2" + " ", Color.black, Color.lime, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB2");

    drawTextAbsolute(14, 14, " " + 1 + "@URL=EFS:ContractSwitch1" + " ", Color.black, Color.white, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB1");
    }
    }

    function main()
    {
    ContractsButton1();

    ContractsButton2();
    }

  • #2
    In case anyone needs this functionality, I changed my code to the following and it works correctly.

    var Contracts = 1;

    function ContractSwitch1(nButtonPressed)
    {
    if(Contracts != 1)
    {
    Contracts = 1;
    }

    ContractsButton1();

    }

    function ContractsButton1()
    {
    if (Contracts == 1)
    {
    drawTextAbsolute(14, 14, " " + 1 + " " + "@URL=EFS:ContractSwitch1", Color.black, Color.lime, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB1"+rawtime(0));

    drawTextAbsolute(17, 14, " " + 2 + " " + "@URL=EFS:ContractSwitch2", Color.black, Color.white, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB2"+rawtime(0));
    }
    }

    function ContractSwitch2(nButtonPressed)
    {
    if(Contracts != 2)
    {
    Contracts = 2;
    }
    ContractsButton2();
    }

    function ContractsButton2()
    {
    if (Contracts == 2)
    {
    drawTextAbsolute(17, 14, " " + 2 + " " + "@URL=EFS:ContractSwitch2", Color.black, Color.lime, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB2"+rawtime(0));

    drawTextAbsolute(14, 14, " " + 1 + " " + "@URL=EFS:ContractSwitch1", Color.black, Color.white, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 11, "CB1"+rawtime(0));
    }
    }

    function main()
    {
    ContractsButton1();

    ContractsButton2();
    }

    Comment

    Working...
    X