Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Button Command (http://www.chiefdelphi.com/forums/showthread.php?t=103634)

Ian McShane 22-02-2012 19:04

Button Command
 
is there a way to end a command when you press a button. EG.
"MoveArmDown" would be a command telling the arm to go down
"End" would be the syntax to end the command
"downSwitch" would be the button

downSwitch.whenPressed(End MoveArmDown)

What would "End" be?

mwtidd 22-02-2012 19:40

Re: Button Command
 
Quote:

Originally Posted by Ian McShane (Post 1132895)
is there a way to end a command when you press a button. EG.
"MoveArmDown" would be a command telling the arm to go down
"End" would be the syntax to end the command
"downSwitch" would be the button

downSwitch.whenPressed(End MoveArmDown)

What would "End" be?

assuming you were using a motor:

buttonA.onPress(new LowerArm())

buttonB.onPress(new StopArm())

LowerArm never actually finishes but rather is interrupted by StopArm


**just make sure they both require the arm subsystem or you may have some explaining to do as to why the arm ate itself.

Sunstroke 23-02-2012 23:59

Re: Button Command
 
You can also do downSwitch.whileHeld(<command goes here>);

The whileHeld method will constantly call start() on the command (which means if the command stops, it will restart, but otherwise there is no difference) while the button is held, and then it will cancel the command when the button is released (so the command will die, calling its interrupt method).


All times are GMT -5. The time now is 09:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi