Skip to main content
Known Participant
May 12, 2018
Answered

UI button programming

  • May 12, 2018
  • 1 reply
  • 678 views

I'm trying to grab a number from the user, default of 1, with buttons next to it that increase or decrease that number

I don't believe I'm even close yet, the number displayed in the UI doesn't change here, also, I'm not sure it's even a number, but text instead.  I'm still very new at this, everything is probably pretty crude.

w = new Window('dialog', "Gadget");

  w.grp1 = w.add('group');

  w.grp1.orientation = "row";

  w.grp1.alignment = "right";

    w.grp1.add("statictext", undefined, "Left Offset:");

    var leftoffset = w.grp1.add("edittext", undefined, 1);

      leftoffset.characters = 3;

      leftoffset.active = true;

    var grp1up = w.grp1.add("button", undefined, "+");

      grp1up.onClick = leftoffset = leftoffset + 1;

    var grp1down = w.grp1.add("button", undefined, "-");

      grp1up.onClick = leftoffset = leftoffset - 1;

Another later goal is to have a checkbox in the UI near the beginning, that allows the button presses to increase the numbers by 0.25's instead of 1's

This topic has been closed for replies.
Correct answer Silly-V

Your onClick code has to be revised to be set to a function like this:

grp1up.onClick = function(){

     leftoffset.text = (leftoffset.text * 1) + 1;

}

the * 1 is to turn the string from UI into a number you can calculate with.

1 reply

Silly-V
Silly-VCorrect answer
Brainiac
May 12, 2018

Your onClick code has to be revised to be set to a function like this:

grp1up.onClick = function(){

     leftoffset.text = (leftoffset.text * 1) + 1;

}

the * 1 is to turn the string from UI into a number you can calculate with.

Known Participant
May 12, 2018

this board hasn't failed me once