PDA

View Full Version : Toggling buttons



Westend
10th March 2010, 08:53 PM
Hi,

I'm pretty new to programming my CH MFP. I have a problem where in my FPS you have to hold the crouch key and the sprint key down to perform those actions.

I wrote a script so that I can toggle the crouch key status and the sprint key status. To keep things in check each sequence checks the status of the other key and if it is set it first releases the other key. I.e When the sprint kye is pressed set the crouch key to false if it is currently set.

This is what I have.


// CMS Script File
//
// Game Title: BF2CC
// Written By: PEter West
// Date: 3/8/2010
//
script

//RESET VARIABLES
IF ( FIRSTSCAN ) THEN
B1 = FALSE;
B2 = FALSE;
B3 = FALSE;
ENDIF

///////////////////////////////////////////////////////
//Toggle Crouch

SEQUENCE

WAIT ( JS1.B6 );

// IF THE SPRINT BIT IS SET THEN TURN IT OFF
IF ( B2 ) THEN
B2 = FALSE;
CMS.B2 = B2; //TOGGLE SPRINT KEY
ENDIF

//TOGGLE CROUCH BIT
IF ( B1 ) THEN
B1 = FALSE;
ELSE
B1 = TRUE;
ENDIF

CMS.B1 = B1; //TOGGLE CROUCH KEY

ENDSEQUENCE

///////////////////////////////////////////////////////
//Toggle sprint

SEQUENCE
WAIT ( JS1.B7 );

// IF THE CROUCH BIT IS SET THEN TURN IT OFF
IF ( B1 ) THEN
B1 = FALSE;
CMS.B1 = B1; //TOGGLE CROUCH KEY
ENDIF

// TOGGLE SPRINT BIT
IF ( B2 ) THEN
B2 = FALSE;
ELSE
B2 = TRUE;
ENDIF

CMS.B2 = B2; //TOGGLE SPRINT KEY

ENDSEQUENCE

endScript

This works fine. However, after forgetting to tap the sprint key to stop sprinting or pressing another key that cancels sprinting I decided that I want to manually hold the sprint key down.

So my challenge is that now when I press the sprint key I still need to detect that the crouch is set and toggle it off. If I set my sprint key button back to the CMC command for sprint then the CMS script no longer detects that button. So I gather that I still need to script the button to set the sprint key to TRUE when it is pressed and set it to FALSE after releasing it.

So whats the best way to script my JS1.B7 so that when it is pressed it sets CMS.B2 to TRUE and when it is released it sets CMS.B1 to FALSE?

Using WHILE() I can set the CMS key to TRUE when the button is pressed. But how to I toggle the state when the key is released?

Best regards,
Pete.

Westend
10th March 2010, 10:59 PM
Aha after some persistance and a lot more reading through the forum I discovered the solution.

I must have done something wrong because initially after setting the sprint key back to programmed mode and applying the CMC setting for sprint the WAIT() did not catch the key. I see that it shoudl still trigger so I tried again.

All I needed to do was to unset the crouch, as I did originally, and nothing else. The Sprint command programmed to the key takes care of the rest.

So here's the script:


// CMS Script File
//
// Game Title: BF2CC
// Written By: PEter West
// Date: 3/8/2010
//
script

//RESET VARIABLES
IF ( FIRSTSCAN ) THEN
B1 = FALSE;
B2 = FALSE;
B3 = FALSE;
ENDIF

///////////////////////////////////////////////////////
//Toggle Crouch

SEQUENCE

WAIT ( JS1.B6 );

// IF THE SPRINT BIT IS SET THEN TURN IT OFF
IF ( B2 ) THEN
B2 = FALSE;
CMS.B2 = B2; //TOGGLE CROUCH KEY
ENDIF

//TOGGLE CROUCH BIT
IF ( B1 ) THEN
B1 = FALSE;
ELSE
B1 = TRUE;
ENDIF

CMS.B1 = B1; //TOGGLE CROUCH KEY

ENDSEQUENCE

///////////////////////////////////////////////////////
//Toggle sprint


SEQUENCE
WAIT ( JS1.B7 );

// IF THE CROUCH BIT IS SET THEN TURN IT OFF
IF ( B1 ) THEN
B1 = FALSE;
CMS.B1 = B1; //TOGGLE CROUCH KEY
ENDIF

ENDSEQUENCE

endScript

vendo
13th April 2010, 02:15 AM
why is it so hard to program keys?

Dace
13th April 2010, 04:10 PM
Glad you got it sorted.

Programing keys or programing macro like behavior.

Programming keys is pretty simple, but the fact that you have a fairly fully featured programming language to do more complex things is absolutely ludicrously awesome :-D ... (I love the word ludicrous)