PDA

View Full Version : %DEFINE Shifted



P51_Rider
1st February 2010, 12:21 AM
Hello all,

Before I start, I have read through the manual once, read the online help page, and even read the Idiiots guide. I have been reading the forums a bunch over the last week, and have integrated many snippets of scripts into my CMS > MAPs.

Programming in the GUI has been a no brainer. But I have been using BIPED with Dhauzimmers drivers for years, and consider myself pretty accomplished in that scripting format. I really want to be proficient at CMS too.

CMS is a little more daunting, but so was BIPED when I started. But I do have one issue that I ran into about a week ago. I solved the issue by using a totally different method ( script ) but keep remembering the previous issue and it is bugging me to no end.

I was trying to %Define a switched mode button with this script.

I have left my comments to myself within the script, but am still not quite sure of some of the issues.


----------------------------------------------------------------------------
Code:

script



// Set Switched Button

//%DEFINE shifted js1.b4 //original definition
%DEFINE shifted (js1.b4) // found at CH Hanger not working either


// Set Modes thru the CMS buttons



sequence



cms.b125 = js1.b10 AND shifted; //try inverting shifted and buttons

cms.b126 = js1.b7 AND shifted; //check to see if I can assign cms buttons this way

cms.b127 = js1.b9 AND shifted;

cms.b128 = js1.b8 AND shifted;







endsequence

sequence

IF( cms.b125 ) THEN

CURRENTMODE = MODE1;

ELSE

IF( B126 ) THEN

CURRENTMODE = MODE2;

ELSE

IF( b127 ) THEN

CURRENTMODE = MODE3;

ELSE

IF( b128 ) THEN

CURRENTMODE = MODE4;

ENDIF

ENDIF

ENDIF

ENDIF

endsequence



sequence



if ([CURRENTMODE == MODE1])

then cms.b1 = js1.b1; //DX1

endif



if ([CURRENTMODE == MODE1])

then cms.b2 = js1.b1 AND shifted; //DX2

endif



if ([CURRENTMODE == MODE2])

then cms.b3 = js1.b1; //DX3

endif



if ([CURRENTMODE == MODE2])

then cms.b4 = js1.b1 AND shifted; //DX4

endif





if ([CURRENTMODE == MODE3])

then cms.b5 = js1.b1; //DX5

endif

if ([CURRENTMODE == MODE3])

then cms.b6 = js1.b1 AND shifted; //DX6

endif





if ([CURRENTMODE == MODE4])

then cms.b7 = js1.b1; //DX7

endif

if ([CURRENTMODE == MODE4])

then cms.b8 = js1.b1 AND shifted; //DX8

endif





endsequence



endScript


---------------------------------------------------

All of the JS were set to DirectX = disabled and none none set in function. CMS buttons were assigned each of the DX buttons correspondingly (B1 - DX1 B2-DX2 and so on).


Each time I ran the script tester, it would give no errors, and no errors when downloading the map.

But when then testing in the Calibration Applet, it would show button 1, then button 2, then button 1 and 2. The response on keypress were eratic and I never saw any button output beyond 1 or 2.

Outside of CH Manager, like in DIView, nothing seemed to work either.

I am using another type of script for the time being, but not understanding why this one didnt work is getting to me, and not understaning makes my future scripts suspect.

After all, one day I aspire to be an UBerScripter like Bob Church or DonULFonso. :salute:


OMT, this scripting is becoming less intemidating, and is actually becoming FUN.

Just trying to shake this one problem so I can move on.

Krenath
6th February 2010, 10:55 PM
New at this myself, but is there any chance that the boolean AND needs to be wrapped in square brackets such as inside the IF() statements?

I don't see anything wrong with your %Define, as my current scripts use it extensively in the same manner you are, so I'm guessing it's not in how you define it but in how you use it.

cms.b125 = [js1.b10 AND shifted]; //try inverting shifted and buttons

Bob Church
7th February 2010, 04:49 AM
Hi Krenath,

>> New at this myself, but is there any chance that the boolean AND needs to be wrapped in square brackets such as inside the IF() statements?

I don't see anything wrong with your %Define, as my current scripts use it extensively in the same manner you are, so I'm guessing it's not in how you define it but in how you use it. <<

No, it shouldn't. You have to use the square brackets when you're doing an arithmetic comparison and need it to return a bit, for example:

b1 = [ js1.b1 > 140 ];

but you shouldn't need to do it with things that are already bits.

>> cms.b125 = [js1.b10 AND shifted]; <<

Exactly how is "shiifted" #DEFINEd. Remember it's text substitution, so if you write:

"#define shifted js1.b4 // js1.b4 is pressed when the shift button is held"

will compile as:

"js1.b1 and js1.b4 // js1.b4 is pressed when the shift button is held".

What exactly is the text in the the #define and in the statement that refers to it?

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

P51_Rider
8th February 2010, 10:53 AM
Krenath said "current scripts use it extensively in the same manner you are"

Would you mind either sending me a copy, or posting a copy, so that I can try to determine where my problem is.

Thanks.

--------------------------------------

Bob Church asked "What exactly is the text in the the #define and in the statement that refers to it?"

I am trying to use the js1.b4 ( as a shift button ) so that when I use the castle hat in a shifted state, it will send the various cms.btns to change to the defined mode for the stick.

In short,

js1.b4 + hat up = cms.b125 which sets mode1
js1.b4 + hat right = cms.b126 which sets mode2

Is this possible ?

Bob Church
8th February 2010, 08:00 PM
Hi P51_Rider,

>> In short,

js1.b4 + hat up = cms.b125 which sets mode1
js1.b4 + hat right = cms.b126 which sets mode2

Is this possible ? <<

Sure. You probably wouldn't want to handle it quite that way since you actually want to change the mode, though. Something more like this would likely work better:


script

// See if the shift button is down.
// Otherwise just skip it.
//
if( js1.b4 ) then

// The shift is down, see if hat up is
// pressed. If it is, set MODE1
//
if( js1.b25 ) then
CURRENTMODE = MODE1;

else

// Hat up isn't pressed, see if hat right is pressed.
//
if( js1.b27 ) then

// It is, set MODE2
//
CURRENTMODE = MODE2;

// Otherwise, we're outta here
//
endIf
endIf
endIf
endScript

That sets the Mode in the script itself. You do need to pick the "Program Settings" tab in the GUI and set the Mode Control device to "CMS". It won't actually switch the LEDs, no script can, but it will set the MODE itself. Buttons 25..32 are the IDs that the CMS script uses to recognize the POV hat positions since they don't have normal GUI button numbers. J1 specifies that you're talking about the hat on the first stick. B25 is "Hat Up", the first position, then they go 'round the hat clockwise to B32 which is Hat Up/Left. It doesn't matter what the POV itself is programmed to do, that will still work, it's just an internal reference. If you don't want to use the POV hat, the position will have a switch ID anyway, just substitute that.

I'm not set up to run it at the moment so let me know if you have any trouble or if you need something to work differently and we can make adjustments.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com