PDA

View Full Version : Need Scripting Help


Misha26
22-11-2004, 01:23 AM
Can some of you cms Gurus please look at this script I made for forgotten battles and pacific fighters. It works, but I'm sure there is a better way to write it and would appreciate some advise.

script

SEQUENCE
WAIT( JS1.B3 ); // Wait until the Yoke Button 3 is pressed.
B1 = NOT B1; // Flip the state of the B1 variable
ENDSEQUENCE

IF( B1 ) THEN // If b1 is TRUE then we're doing Engine 1 so
CMS.A1 = JS2.A1; // copy Throttle 1 axis,
CMS.A2 = JS2.A3; // and Prop 3 axis to the CMS Axis.
ENDIF

SEQUENCE
WAIT( JS1.B4 ); // Wait until the Yoke Button 4 is pressed.
B2 = NOT B2; // Flip the state of the B2 variable
ENDSEQUENCE


IF( B2 ) THEN // If b2 is TRUE then we're doing Engine 2 so
CMS.A1 = JS2.A2; // copy Throttle 2 axis,
CMS.A2 = JS2.A4; // and Prop 4 axis to the CMS Axis.
ENDIF

endScript

What it does is:
when I move the rocker switch on the flightsim yoke left (B3), TQ A1 works as Throttle and TQ A3 as Prop
when I move the rocker switch on the flightsim right (B4), TQ A2 works as Throttle and TQ A4 as Prop

Notes:
Yoke Buttons 3 and 4 are assigned in the control manager as follows:
Yoke B3 press is select left engines B3 released is unselect all engines;
Yoke B4 press is select left engines B4 released is unselect all engines;

JS1 is Yoke
JS2 is Throttle Quad

Another thing I've been trying to add to this script (but can't figure it out) is that when the rocker switch is neutral, I want the "select all engines command" to be activated so that I can move both throttle (or Prop) levers together when I don't need descreet control of each engine. So I'm looking for help here as well.

Thanks in advance.

Misha26
22-11-2004, 01:50 AM
I did some more testing and noticed that the sometimes you need to select left of right engines more than once before the appropriate axis becomes active in the sim.

Bob Church
22-11-2004, 04:38 AM
Hi Misha,

You've really done about all you can do. The problem with all of the schemes for switching engines and controls like that is that there's no way to guarantee that you pushing a button on the yoke will line up with the sim looking for the change in an input. The sim only checks periodically, once per frame, and you can't really know up front whether the sim is going to pick up the axis value before or after the engine change. Internally somewhere it picks up the axis value and somewhere it looks for the engine switch, but which one it checks for first just depends on the sim. Also, you mention using the yoke buttons to select the engines. If you're sending characters to do that, those are going to arrive in the sim more slowly than the axis and button changes since characters have to be queued up and it takes time for them to be sent.

You might look at the thread a couple of threads down in this section started by Abe Beson. He's working on essentially the same problem, getting multiple throttles into a single input axis and keeping it sync'd so that the sim is controlling the engine that you're sending control inputs to. That same timing is likely why you're having it miss the engine switchover.

WRT to setting both engines, you'd basically want something like:

CMS.B1 = NOT JS1.B3 AND NOT JS1.B4;

CMS.B1 just turning on when neither side of the rocker is closed. It probably needs to be a bit more elaborate, though, with some kind of delay so that it doesn't generate a "Select All" command while you move from one side to the other. An ONDELAY probably:

TIMER( ONDELAY, D1, 20 ) = NOT JS1.B3 AND NOT JS1.B4;
CMS.B1 = D1;

would work if you're using characters, you'd need to tag a NULL on the "all engines" command so it didn't repeat on you. For DX Buttons to select, you'd probably want a second timer:

TIMER( ONDELAY, D1, 20 ) = NOT JS1.B3 AND NOT JS1.B4;
TIMER( PERIOD, D2, 1 ) = D1;
CMS.B1 = D2;

so that CMS.B1 just clicked on for a short time and then turned off again.

there is a basic problem with both in that you end up having to hold down the rocker while you do single engine adjustments, though, since a short time after you take your finger off the rocker it's going back to "all engines" again. You might set up some sort of detection logic that watched for activity on the separate throttles and held the timers off so that it would wait until you were done moving the levers.

- Bob

The StickWorks
http://www.stickworks.com

Misha26
22-11-2004, 05:16 AM
Thanks for the detailed response Bob.
I'll try your suggestions.

I did use Abe's script before but couldn't get it working. I know a little bit more now about the Control Manager and CMS so maybe I'll give it another go.

Cheers.

Originally posted by Bob Church@Nov 22 2004, 03:38 AM
Hi Misha,

You've really done about all you can do. The problem with all of the schemes for switching engines and controls like that is that there's no way to guarantee that you pushing a button on the yoke will line up with the sim looking for the change in an input. The sim only checks periodically, once per frame, and you can't really know up front whether the sim is going to pick up the axis value before or after the engine change. Internally somewhere it picks up the axis value and somewhere it looks for the engine switch, but which one it checks for first just depends on the sim. Also, you mention using the yoke buttons to select the engines. If you're sending characters to do that, those are going to arrive in the sim more slowly than the axis and button changes since characters have to be queued up and it takes time for them to be sent.

You might look at the thread a couple of threads down in this section started by Abe Beson. He's working on essentially the same problem, getting multiple throttles into a single input axis and keeping it sync'd so that the sim is controlling the engine that you're sending control inputs to. That same timing is likely why you're having it miss the engine switchover.

WRT to setting both engines, you'd basically want something like:

CMS.B1 = NOT JS1.B3 AND NOT JS1.B4;

CMS.B1 just turning on when neither side of the rocker is closed. It probably needs to be a bit more elaborate, though, with some kind of delay so that it doesn't generate a "Select All" command while you move from one side to the other. An ONDELAY probably:

TIMER( ONDELAY, D1, 20 ) = NOT JS1.B3 AND NOT JS1.B4;
CMS.B1 = D1;

would work if you're using characters, you'd need to tag a NULL on the "all engines" command so it didn't repeat on you. For DX Buttons to select, you'd probably want a second timer:

TIMER( ONDELAY, D1, 20 ) = NOT JS1.B3 AND NOT JS1.B4;
TIMER( PERIOD, D2, 1 ) = D1;
CMS.B1 = D2;

so that CMS.B1 just clicked on for a short time and then turned off again.

there is a basic problem with both in that you end up having to hold down the rocker while you do single engine adjustments, though, since a short time after you take your finger off the rocker it's going back to "all engines" again. You might set up some sort of detection logic that watched for activity on the separate throttles and held the timers off so that it would wait until you were done moving the levers.

- Bob

The StickWorks
http://www.stickworks.com
<div align="right">8407
[/quote]