to determine the button is pressed or not pressed

YudinEdYudinEd Posts: 90

Hi!

How can I determine the button is pressed (clicked, released)  or not pressed (not clicked, not released) with help of script?

Post edited by YudinEd on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,871
    edited February 2017

    You need to create a function to handle button presses and use the Connect function to link it to the clicked() signal for the button - which is emitted when the button is presed and released. The function could do whatever you want, from simply setting a variable to indicate that the press occured to reconfiguring the dialogue or data state. http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/signals_slots/start

    Post edited by Richard Haseltine on
  • YudinEdYudinEd Posts: 90
    edited February 2017

    Hi, Richard Haseltine!

    I'm glad you answered me.

    I understand sense, but unfortunately badly I know the script syntax. How to link the letters into a single whole :)

    A small script example would help me ( even untested).

    I'm trying to do it:

    Button is pressed (finger on the button ) and I have an infinite action. The button is released (remove your finger from the button) - action stops

    So I have 2 strings 

    // to create Button and connects with my Functions. Signals - pressed(), released()

    connect (MyButton, "pressed()", myPressedFunction;

    connect (MyButton, "released()", myReleasedFunction;

    I think that correctly understand the logic -

    if true (button pressed) then function myPressedFunction

    else (false) then function myReleasedFunction.

    I tried different variants (I will not give examples, so you do not laugh laugh), but I could not keep track when removed finger from the button - the action does not stop. 

    Please little exаmple . Thank you in advance

     

    Post edited by YudinEd on
  • I think you need something to keep the incremnts happening separate from the button actions - I added a DzTime (using the code snippet from the Connect documentation in the DS3 docs as a starting point and this seems to work:

    // DAZ Studio version 4.9.3.166 filetype DAZ Script// Advance a counter while the button is held down, show in dialogue    // A function to set the advance flag to on and start the timer    function startAdvance(){        advancing = true;        incSpeed.start( 1000 );    }        // A function to set the advance flag to off and stop the timer    function stopAdvance(){        advancing = false;        incSpeed.stop();    }        // A function to increment the counter and update the label    function increment () {    	// Shouldn't need the flag, but it adds a safety feature    	if ( advancing ) {    		counter++;    		wCounter.text = "%1".arg( counter );    	}    }		var counter = 1;	var advancing = false;	    // Create a dialogue    var wDlg = new DzDialog;    var wDlgLyt = new DzVBoxLayout( wDlg );    wDlgLyt.autoAdd = true;    var wBtn = new DzPushButton( wDlg );    wBtn.text = "Press to increase";    var wCounter = new DzLabel( wDlg );    wCounter.text = "%1".arg( counter );        // Connect the DzButton::pressed() signal to the start advance function    // and released to stop advance    connect( wBtn, "pressed()", startAdvance );    connect( wBtn, "released()", stopAdvance );            // Create a timer parented to the dialogue and link to the increment function    var incSpeed = new DzTimer( wDlg );    connect( incSpeed , "timeout()" , increment );    // Display the dialog    wDlg.exec();

     

  • Timer!     devil

    It is a good idea and works perfectly. My thanks.

Sign In or Register to comment.