PDA

View Full Version : CM Script Issues


Ding
10-01-2004, 06:15 AM
I'm just getting started with CMS and this script is giving me some considerable trouble. I was wondering if anyone here could assist me with it.

The game this script file is for has a communications interface which can be opened with C (assigned to CMS.B11 - fires on press and release). At this point, you are presented with several options which can be chosen using keys 1-9 (assigned to CMS.B1-B9 respectively). There is also a Back option accessible by pressing 0 (CMS.B10). I would like to be able to control this interface entirely from the HOTAS without actually dedicating 10 buttons to the comms. This script is meant to set up the pinky button on the Fighterstick (JS1.B4) as a shift - when it is activated, the comm interface is brought up. I would then be able to "select" the needed option using Hat2-up (JS1.B9) and Hat2-down (JS9.B11). Pressing Hat2-right (JS.B10) would activate the selected command, and Hat2-left (JS.B12) would activate the Back command (assigned to CMS.B10). While the pinky button is off, Hat2 returns to normal operation.

The code:

script

SEQUENCE
Â*Â*Â*Â*WAIT(JS1.B4 AND NOT B1);
Â*Â*Â*Â*B1=TRUE;//comms interface activated
Â*Â*Â*Â*
Â*Â*Â*Â*CMS.B11=TRUE;//open comms interface
Â*Â*Â*Â*
Â*Â*Â*Â*WAIT(JS1.B9 OR JS1.B10 OR JS1.B11 OR JS1.B12 OR JS1.B4 AND NOT B1);
Â*Â*Â*Â*
Â*Â*Â*Â*IF(NOT JS1.B9 AND NOT JS1.B10 AND NOT JS1.B11 AND NOT JS1.B12 AND JS1.B4 AND NOT B1) THEN
Â*B1=TRUE;//comms interface activated
Â*CMS.B11=TRUE;//open comms interface
Â*Â*Â*Â*ENDIF
Â*Â*Â*Â*
Â*Â*Â*Â*IF(JS1.B12) THEN//back
Â*CMS.B10=FALSE;//send back command
Â*CMS.B10=TRUE;
Â*Â*Â*Â*ENDIF
Â*Â*Â*Â*
Â*Â*Â*Â*IF(JS1.B9) THEN//decrement
Â*A1=A1-1;
Â*Â*Â*Â*ENDIF
Â*Â*Â*Â*
Â*Â*Â*Â*IF(JS1.B11) THEN//increment
Â*IF([A1<4]) THEN
Â*Â*Â*Â*Â*A1=A1+1;
Â*ENDIF
Â*Â*Â*Â*ENDIF
Â*Â*Â*Â*
Â*Â*Â*Â*IF(JS1.B10) THEN//commit
Â*CMS.B1=[A1==0];
Â*CMS.B2=[A1==1];
Â*CMS.B3=[A1==2];
Â*CMS.B4=[A1==3];
Â*CMS.B5=[A1==4];
Â*
Â*CMS.B11=FALSE;//close interface
Â*
Â*A1=0;
Â*B1=FALSE;//comms interface deactivated
Â*Â*Â*Â*ENDIF
ENDSEQUENCE

IF(NOT JS1.B4 AND B1) THEN//comms interface open, but shift is not held down
Â*Â*Â*Â*CMS.B11=FALSE;//close interface
Â*Â*Â*Â*
Â*Â*Â*Â*B1=FALSE;
ENDIF

IF(NOT JS1.B4) THEN//normal hat operation
Â*Â*Â*Â*A1=0;

Â*Â*Â*Â*CMS.B12=JS1.B9;
Â*Â*Â*Â*CMS.B13=JS1.B11;
Â*Â*Â*Â*CMS.B14=JS1.B10;
Â*Â*Â*Â*CMS.B15=JS1.B12;

Â*Â*Â*Â*CMS.B1=FALSE;
Â*Â*Â*Â*CMS.B2=FALSE;
Â*Â*Â*Â*CMS.B3=FALSE;
Â*Â*Â*Â*CMS.B4=FALSE;
Â*Â*Â*Â*CMS.B5=FALSE;
ENDIF
endScript

At the moment it's only implemented for the first five buttons, but extending it will be trivial once the script is fixed.

A1 keeps track of the currently selected option and B1 indicates whether the comm interface is currently open. Over the past several hours I have gone through a handful of revisions of this script, and this one seems to be the closest to working. The shift functionality works, as does the unshifted functionality of the hat, but the rest of it is having major problems which I can't figure out. Coming from a proper programming background, I'm lost without a debugger or at least the ability to include debug messages. :)

Perhaps my problem comes from misunderstanding the basic structure of CMS, and I'd love it if someone could enlighten me to the proper way of setting up this particular script.

Thanks.

MarkShot
10-01-2004, 03:56 PM
I agree having to program without a debugger is a pain.

Two suggestions:

(1) Use the key check and axis calibration utilities a lot to observe results and as opposed to testing in the game. You'll get a better understanding of what is going on.

(2) Do your development in small iterative steps. (The interpretted programming model as opposed to the compile/link programming development model.)

---

I think I see one problem in your script. Don't ask me why, because I just wrote my first programs a week ago. You need to have a delay between the enabling of a character and the disabling of a character. Like:

CMS.B1 = TRUE;
DELAY(1);
CMS.B1 = FALSE;

I suspect if you don't the character is emitted so fast that it is never actually seen.

Ding
10-01-2004, 04:22 PM
I don't think that's the problem. The only controls I'm doing that for are the ones that fire only on the press, so the first release shouldn't do anything.

Bob Church
10-01-2004, 04:59 PM
You can try this, maybe it will work a little better. There were a few bugs in the original but I suspect that the main problem was that you can't turn an output on and back off in the same pass through the CMS script and have it propagate to any output. It has to be maintained or at least one frame. I've added a couple of delays to let that happen. The delay instructions are in terms of character scan times (set in the Program Settings tab). I set the delays at two scans, but they may need some fiddling.

The other things that are a little unclear are first the "backing up" thing with cms.b10. It operates just one time on js1.b12 until you release and then reclose js1.b4. The other thing that looks a little odd is that cms.b11 turns off as soon as you commit, but the selected output doesn't turn off until you release js1.b4. I'd have expected that the cms.b11 output would bracket the selected outputs, but I don't really know.

Otherwise, it's still pretty close to what you had originally. Sorry for the unquoted code, that tidy white code box apparently requires Javascript to set up and I don't have it installed.

>>
script
sequence
delay( 2 ); // sets a 2 scan hold on cms.b10
cms.b10 = FALSE; // this is already false most of the time

wait( js1.b9 or js1.b10 or js1.b11 or js1.b12 and ( js1.b4 and not b1 ));

b1 = true; // comms interface activated
cms.b11 = true; // open comms interface

if( js1.b12 ) then // back up
cms.b10 = true;
endif

if( js1.b9 and [ a1 > 0 ] ) then // decrement the selection
a1 = a1 - 1;
endif

if( js1.b11 and [ a1 < 4 ]) then // increment the selection
a1 = a1 + 1;
endif

if( js1.b10 ) then // commit
cms.b1 = [ a1 == 0 ];
cms.b2 = [ a1 == 1 ];
cms.b3 = [ a1 == 2 ];
cms.b4 = [ a1 == 3 ];
cms.b5 = [ a1 == 4 ];
a1 = 0;
b1 = false; // comms interface deactivated
endif
delay( 2 ); // hold cms.b11 for 2 additional scans
cms.b11 = b1; // clear it if b1 cleared
endsequence

if(( not js1.b4 ) and b1 ) then // comms interface open but no shift
cms.b11 = false; // close interface
b1 = false;
endif

if(not js1.b4) then // normal hat operation
a1=0;
cms.b12 = js1.b9;
cms.b13 = js1.b11;
cms.b14 = js1.b10;
cms.b15 = js1.b12;
cms.b1 = false;
cms.b2 = false;
cms.b3 = false;
cms.b4 = false;
cms.b5 = false;
endif
endscript
<<

- Bob

The StickWorks
http://www.stickworks.com

Ding
10-01-2004, 11:23 PM
Thanks for all your help, Bob. After a few more hours of tweaking, I was finally able to iron out all the issues with the script. Here's the (mostly) final code:


script
Â*Â*Â*Â*sequence
Â*while( js1.b4 );

Â*if( not b1 ) then // shift is held, but interface not open; open interface
Â*Â*Â*Â*Â*b1 = true;
Â*Â*Â*Â*Â*cms.b11 = true;
Â*endif

Â*wait( js1.b9 or js1.b10 or js1.b11 or ( js1.b4 and not b1) );

Â*if( js1.b4 and not b1 ) then // interface closed while waiting for hat input; reopen
Â*Â*Â*Â*Â*b1 = true; // comms interface activated
Â*Â*Â*Â*Â*cms.b11 = true;
Â*endif

Â*if( js1.b9 and [ a1 > 0 ] ) then // decrement the selection
Â*Â*Â*Â*Â*a1 = a1 - 1;
Â*Â*Â*Â*Â*b2 = false;
Â*endif

Â*if( js1.b11 and [ a1 < 8 ] ) then // increment the selection
Â*Â*Â*Â*Â*a1 = a1 + 1;
Â*Â*Â*Â*Â*b2 = false;
Â*endif

Â*if( js1.b10 ) then // commit
Â*Â*Â*Â*Â*cms.b1 = [ a1 == 0 ];
Â*Â*Â*Â*Â*cms.b2 = [ a1 == 1 ];
Â*Â*Â*Â*Â*cms.b3 = [ a1 == 2 ];
Â*Â*Â*Â*Â*cms.b4 = [ a1 == 3 ];
Â*Â*Â*Â*Â*cms.b5 = [ a1 == 4 ];
Â*Â*Â*Â*Â*cms.b6 = [ a1 == 5 ];
Â*Â*Â*Â*Â*cms.b7 = [ a1 == 6 ];
Â*Â*Â*Â*Â*cms.b8 = [ a1 == 7 ];
Â*Â*Â*Â*Â*cms.b9 = [ a1 == 8 ];
Â*Â*Â*Â*Â*a1 = 0;
Â*Â*Â*Â*Â*b2 = true;Â*Â*Â*Â*// comms window automatically closes after the final commit
Â* Â* Â*// b2 indicates that the window is potentially closed at this point
Â*endif

Â*delay( 2 ); // clear the comms buttons after 2 scans
Â*cms.b1 = false;
Â*cms.b2 = false;
Â*cms.b3 = false;
Â*cms.b4 = false;
Â*cms.b5 = false;
Â*cms.b6 = false;
Â*cms.b7 = false;
Â*cms.b8 = false;
Â*cms.b9 = false;
Â*Â*Â*Â*endsequence

Â*Â*Â*Â*if( not js1.b4 ) then // normal hat operation
Â*if( b1 ) then // comms interface open, but no shift
Â*Â*Â*Â*Â*if( not b2 ) then // last operation a commit; comms window is probably closed, so don't send a close
Â* Â*cms.b11 = true; // close interface
Â*Â*Â*Â*Â*endif
Â*Â*Â*Â*Â*b1 = false; // whatever the situation, the window is gone by now
Â*Â*Â*Â*Â*a1 = 0;
Â*endif

Â*cms.b12 = js1.b9;
Â*cms.b13 = js1.b11;
Â*cms.b14 = js1.b10;
Â*cms.b15 = js1.b12;
Â*Â*Â*Â*endif

Â*Â*Â*Â*if( cms.b11 ) then
Â*sequence
Â*Â*Â*Â*Â*delay( 2 ); // automatically clear cms.b11 2 scans after activation
Â*Â*Â*Â*Â*cms.b11=false;
Â*endsequence
Â*Â*Â*Â*endif
endscript

Not too far off from your version, but with some big logic errors fixed and functionality added. Though in the end I realized that this script has an irrepairable flaw: after you commit the final command (actually send a command as opposed to selecting a category of commands), the game automatically closes the comm window and I have no idea if it's still up. Right now, the script basically guesses based on your last input, and this should work in most situations. I just hope I don't suddenly forget this little quirk in the heat of battle. :unsure:

CMS is great! I just wish ControlManager had better support for external editors (a command-line client for checking syntax and downloading the data to the stick would make my day).

Bob Church
11-01-2004, 03:49 AM
>> Thanks for all your help, Bob. After a few more hours of tweaking, I was finally able to iron out all the issues with the script. <<

You're more than welcome, Ding! I'm glad it was some help. It was kind of an intriguing problem, trickier than it sounded at first.

>> Here's the (mostly) final code... <<

Got it! I'll have to take a look a bit later and see where it went. Mine was a little hit-or-miss, there were some places where I wasn't really sure what you were trying to accomplish and so just took my best guess.

>> Not too far off from your version, but with some big logic errors fixed and functionality added. Though in the end I realized that this script has an irrepairable flaw.... <<

I hate when that happens.<g>

>>...after you commit the final command (actually send a command as opposed to selecting a category of commands), the game automatically closes the comm window and I have no idea if it's still up. <<

I suppose it's been lost too if you were to just reopen it on the same button. Did you notice whether the screen closed on the press or on the release? If it's the release that closes it, maybe you can just hold the key down until you release js1.b4?

>> CMS is great! I just wish ControlManager had better support for external editors (a command-line client for checking syntax and downloading the data to the stick would make my day). <<

Yeah, I've thought about that too. You never know, something might come along. You can edit the CMS files with a different editor if you create the map first so the MAP and CMS files exist. The Control Manager will overwrite the CMS file when it does create the map if you don't. I usually just start the map, add the devices, make whatever GUI assignments I need, then save it and use an old DOS editor for the initial CMS file. I go back to the GUI once it's written for testing and tweaking. It works okay for me, but I do the same thing for other programming so I'm used to it.

Anyway, good to hear you got it sorted out!

- Bob

The StickWorks
http://www.stickworks.com