TARGET - Advanced programming - ED Forums


Thread Tools Display Modes
Old 05-04-2011, 05:10 PM   #1
Join Date: Apr 2011
Location: France - Limours
Posts: 310
Default TARGET - Advanced programming

Here are some of my major proficient elements good to consider when dealing with TARGET scripting. And I mean when you want to go beyond Thrustmaster FAST SCRIPT BASIC document.

The intent is to add some clues to what comes out from experimenting with the language after having read this and messed up with what you think the meaning was.

The main intent of the author seems to be about making explanations as simple (i.e. short) as possible in order to avoid frightening readers... Results is there are so many missing parts that your guesses are the only way out, like if 20% of A-10's cockpit buttons were not documented.

My starting point was to use TARGET to improve the use of a perfectly working HOTAS that does not require it in any way. To do that, I had to come up with a clean working base. And the documentation was not helpful here.

To start with something immediately useful, here is the most basic lesson I learned from the experience:

Making good use of preprocessing include directive helps at improving readability in several ways:

- Lightens and compacts calling code with the effect of displaying the big picture.

- Confines related code into a dedicated file where it can be isolated from irrelevant code.

  • Here are a few topics organized into their own separate files:
    include "target.tmh"              // Target's own definitions
    include "js/js_map.tmc"           // ...separate custom code
    include "th/th_map.tmc"           // ...throttle mapping detail
    include "axis/util_axis_map.tmc"  // ...MapAxis() calls
    include "axis/util_KeyAxis.tmc"   // ...keyAxis() calls
    ...those files can use their own relevant include organization as well.

  • Optional functions files may be included too:
    include "view/util_view.tmc"
    include "util/util_led.tmc"
    include "util/util_log.tmc"
    ...activating and deactivating those optional functions would only require commenting out a one-liner call to the freezed function from main code. The alternative beeing a whole bunch of freezed commented code lines.

  • The standard main script entry point specifying two modifier switches for IO and UMD layers:
    int main()
    	// Init
    		return 1;
    	SetKBRate(25, 33);
    	// Layer shift switches S3 and S4
    	  &Joystick, S4      // devI    , indexI
    	, &Joystick, S3 , 0  // devUMD  , indexU, indexD
    	, 0);                // flag (IOTOGGLE + UDTOGGLE)
    ...&Joystick, S4
    Means holding joystick S4 switch down while activating another js or th switch asks TARGET to generate it's I(in) layer mapped virtual input event (instead of the default O(out) one).

    ...&Joystick, S3
    Same idea applies for the U(up) layer mapping.
    , 0 is where an D(down) layer modifier would be specified.

    ..., 0
    - Default (0) has layer shift while holding shift buttons (modifiers / reformers)
    - IOTOGGLE, UDTOGGLE toggles layer combination in effect on/off each time you hit one

  • The mapping part: [PHYSICAL SWITCHES] to generated [PROCESS INPUT EVENTS] (keyboard + DX-Input):
    printf("DCSW_main:\xa"); // A clue about script activity in editor's trace panel
    js_map();                // Calling a function defined in the included "js/js_map"
    th_map();                // ...same for throttle mapping
    util_axis_map();         // ...and axis mapping
    util_KeyAxis();          // ...virtual keyboard events based on specified axis values
    init_LED(&Throttle);     // ...playing with console LEDs
    printf("...ready\xa");   // Just to know we're there, not trapped into some dead-lock

  • Handling [button press / release] entry point:
    int EventHandle(int type, alias o, int x)
    	if(log_level > 0) {
    		if((x < IN_POSITION_AXES) & o[x])
    			log_event(&o, x);
    	DefaultMapping(&o, x);
    Here we have a chance to interfere before the virtual input mapped to each switch gets delivered to the focussed process (*).

    In this case, the code does not change anything to the standard handling. It just calls a function that prints details about what's happening when switch activation handling is carried out. The log_event() function is in the "util/util_log.tmc" included file (shows selected layer, switch number, ...).

    In fact, this is where we can add some tricks that would override standard TARGET features (...)

I have more experimental (painfully obtained) information to share but it will be better discussed when appropriate rather than adding to this first post... that I hope it's still readable

(*) During script test sessions, your focused window will direct generated virtual events to the owning process. A good idea is to always click EventTester's window before pressing any button as it is prepared to ignore anything you throw at it.

As it is my first contribution to the forum, I made this post as a compilation of what brings me here and I intend to reorganize it in the near future.

Topic subject is about TARGET advanced programming (early steps) but I need to state who's talking in order to make myself clear about why this post and what I expect from readers.

BTW, I'm french, so...

To say the least, I'm quite new at sim's! In fact I have everything to learn as my only background is some playing around with FS ages ago. But, as I took the (good!) time to read posts telling newbies how to behave, I think I'm ready to contribute with something useful ...and hopefully get some contributing input in return.

At this time, I had to show up because I went as far as I could with my non-existent experience on the main subject (DCS per se).

In fact, this TARGET SCRIPT exploration of mine has been my first motivation at getting my hands on a Thrustmaster HOTAS. I was amazed by all these buttons and the level of user programming Thrustmaster released. All my previous experience with Logitech software has been so disappointing that I was not expecting such level of consideration from any hardware manufacturer.

Then, I stumbled upon DCS A-10C ED's simulator (early 2011 was just the right time ) and I could not resist at downloading it. And I'm really happy I failed!

From my reading so far, I could see that experienced simmers are rather envious of newcomers at the discipline as the journey from startup to mastering the beast is the best part. ...Lucky me!

As such, any serious major choices I'm about to make at this stage of my INPUT programming requires sound decisions. Like for example which buttons would be best dedicated at TARGET IOUMD layers switching that would be the least interfering with mission tasks... That's where i'm a total noob and this is the rationale of this post, aside from the pleasure to share what I'm best prepared to contribute thanks to my knowledge... I'm no airline pilot, but I know my way around computers, that's why.

...all this needs being relocated to some presentation thread. I'm aware of it! ...will do.

My student journey had me motivated to gather information published by others and I shared my harvest in these User Files:But my code the most relevant to this post is the one attached bellow. I did not upload it elsewere yet because it's my working copy and as such is going to become obsolete everyday!

...updated TM_Warthog_Combined_1111_ivanwfr.lua
... * DX Input OFF button events have no effect :( *

 + H2U + TG1_MO  + flashLED() // PAC auto zoom 
 + H4U_DO = USB_QUOTE;                // Score window
 + H4R_DO = USB_QUOTE+ L_SHIFT;       // Show debriefing window
 + H4P_MI = USB_M    + L_CTL;         // Master Caution

... js_SHIFT() & th_SHIFT() called later, in order to override earlier standard mapping.
... Console back light Intensity & On/Off
... Up-Out layer updated: Eject, Respawn, Frame rate, Active Pause
... Joystick with SetCurve(zoom) with S3
 - Hold S3 = Joystick Precision temporary mode (like TrackIR does)
 - Hold S3 + Friction Control : Adjust and retain zoom (Full forward = 100% deviation)
 - ... removed curvature adjustment (no need for TM Warthog)

... Adjusted snap-views key down timer from default 32ms to 50ms - (110613)
 * works much better (as in every time) with my rig (i7 960 + W7x64)
... Adjusted hat corner handling -- Throttle CS and Joystick H[1234] [URDL] - (110612)
... Added th_DX_main.tmc for a simple DirectInput Trottle Mapping
 * needs loading related profile *
... Adjusted P&P profile for Patch-1108
... China Hat that won't go in corners (...and disrupt Left Long Press = SOI)
... Hats in corners
... Slew keying/mousing tuned by Friction-Control
... DCSW_PNP_main.tmc as a bare PnP starting point
... Slew / Trackpad mouse pointer freezing with S3 for a stable Left-Click.
...TARGET Combined plug and play as an alternative to separate USB devices
Joystick+Throttle HOTAS Warthog Game Controllers
...Keyboard dynamic HTML for IOUMD layers bindings

Note : All of this has been smartly sabotaged with patch
Attached Thumbnails
Click image for larger version

Name:	Event_Tester_PNP.png
Views:	2163
Size:	41.6 KB
ID:	51395   Click image for larger version

Name:	MI.png
Views:	3067
Size:	151.1 KB
ID:	56896   Click image for larger version

Name:	MO.png
Views:	1918
Size:	201.5 KB
ID:	58295  

Click image for larger version

Name:	UI.png
Views:	1496
Size:	115.0 KB
ID:	58296   Click image for larger version

Name:	UO.png
Views:	1731
Size:	158.7 KB
ID:	58297   Click image for larger version

Name:	DI.png
Views:	1662
Size:	162.3 KB
ID:	58298  

Click image for larger version

Name:	DO.png
Views:	1448
Size:	141.2 KB
ID:	58299  
Attached Files
File Type: zip (37.9 KB, 621 views)
File Type: zip (162.0 KB, 811 views)
File Type: rar DCS_Bindings_110924.rar (2.01 MB, 983 views)
File Type: zip (40.3 KB, 356 views)
File Type: zip (215.8 KB, 448 views)

Last edited by ivanwfr; 01-08-2012 at 01:01 PM. Reason: spelled organized correctly instead of organizsed ^^
ivanwfr is offline   Reply With Quote
Old 05-04-2011, 08:20 PM   #2
Join Date: Feb 2006
Location: Bretagne / France
Posts: 390

nice demonstration of the flexibility of the Script
dimebug is offline   Reply With Quote
Old 05-05-2011, 11:25 PM   #3
Join Date: Apr 2011
Location: France - Limours
Posts: 310
Default Adjusting and Saving Cockpit Angles ruled by thumb

Starting from the structured mapping code attached - and updated - to my first post, I could introduce an automated handling of DCS\Config\View\SnapViews.lua.

DCS Command is:
[Save Cockpit Angles] category [View Cockpit]: [Save current cockpit camera angles for fast numpad jumps]


This feature does not seem to be fully implemented yet as the configuration is not saved in user profile space as it should... for instance:
C:\Users\<your_login_name>\Saved Games\DCS Warthog\Config\View
...would be appropriate, I guess.

Instead, your views are saved in one of DCS program default configuraton folder:
<install_dir>\DCS\Config\View in a file named SnapViews.lua

This is where the 10 snap views corresponding to Num0-Num9 of the Number pad are defined (and can be adjusted) (and 3 more views are there for mirrors).

But, in fact, they're never saved, anywhere, as this can happen only after you unlock the feature as explained below.

Another little but weird detail to consider, is that you need to modify a variable defined in the View.lua program file you can find in the same folder in order to have the command effectively do something!

Even if you map some input event to "Save Cockpit Angles", there is a default directive telling the program to ignore this command. To change this, you have to modify one line of View.lua.
Line 50 says:
UseDefaultSnapViews = true
...and it should read:
UseDefaultSnapViews = false we want our SnapViews.lua file used instead of the one named SnapViewsDefault.lua!

At this point, we can hit R_ALT + Num0 and have our SnapViews.lua updated when program exits. (Beware, this file is created only when you terminate your session).

As a side note some helpful information can be found in SnapViewsDefault.lua but unfortunately, there is a twist in the comment you find there (merely a missplace punctuation in fact):

User-made snap views for all his missions are saved 
in the Config/View/SnapViews.lua file if the parameter
DisableSnapViewsSaving = true in the Config/View/Cockpit.lua file.
Default snap views come from the Config/View/SnapViewsDefault.lua file.
...should read:

User-made snap views for all his missions are saved in the Config/View/SnapViews.lua file.
If the parameter DisableSnapViewsSaving = true in the Config/View/Cockpit.lua file,
default snap views come from the Config/View/SnapViewsDefault.lua file.

...and that's precisely what we don't want!

Using [Save Cockpit Angles]:

Still, even if you can redefine your views, it's not a friendly process. If ED did not advertise much about this it's for a reason, and I guess it's because the procedure is currently pretty tricky:

When you hit [R_ALT + Num0], what you're saving is the last selected predefined view you've displayed before you started ajusting the camera.
This means you must not inadvertently use any of those views while you're making your camera adjustements. If you do, you're going to modify the wrong one.


This is where my TARGET script comes to the rescue... Well it will be adequate only for those who are ready to use TARGET with a compatible HOTAS! ...and get their hands dirty during the process ...and are still reading.

I based the Save Cockpit Angles function on the SNAP VUE [LOOK]-[SELECTION] mechanism I've put in there earlier.

What it does right now is this:

- The selection of one of those views can be made with the 4 HATS/POV of a Warthog HOTAS.

- After having carefully adjusted the position of the camera in the cockpit, the next HAT-SELECTED view can be instantly modified (and later saved) by pressing [S4 + S3 + S2] (cat + drunk-pilot proof combos!).

... just follow the maze:

S4 (Middle-In layer shift)
-> see [H1234] mapping of js/js_MI_view.tmc
-> will call view_look_start, view_look_end, view_select, unlock_view of view/view_cockpit.tmc

S3 (Up-In layer shift)
-> see [S2] mapping of js/js_UI_view.tmc
-> will call view_save_selected of view/view_cockpit.tmc

These steps are not frienly either (at first) but I wanted to share my raw results early. If they draw more than my own curiosity, I'm ready to get into more details for those interested.

Quick steps to make that work:

(Dont' shoot, I will elaborate/adjust on request...)

- Combined_ivanwfr.lua: In order to have TARGET virtual HOTAS work at least like the TM Warthog 2 separate devices mapping with DCS A-10C, you have to import those DCS corresponding commands.

It comes as the result of an initial mapping session profile with a keyboard shortcut bound to each Joystick button keeping all 32 DX-input available for Throttle mapping.

(BTW... have a look there to see a note about [Flight Control] JOY_BTN3 messed up between joystick and throttle... still have to issue a ticket about that.)

- Launch TARGET Script Editor and load and run view_main.tmc or DCSW_main.tmc

- Then do some reading of the most relevant code in these files:
- view_main.tmc
- js/js_MI_view.tmc
- js/js_UI_view.tmc
- view/view_cockpit.tmc

I think I've much to do for all that to make sense to no geek-like-me but it's all a work in progress.

...don't hesitate to ask about all that I intentionally avoided to talk about... (this post is long enough )


    |       util_assoc.tmc
    |       util_assoc_init.tmc
    |       util_assoc_keys.tmh
    |       util_assoc_log.tmc
    |       util_assoc_main.tmc
    |       util_assoc_map.tmc
    |       axis_key_map.tmc
    |       axis_map.tmc
    |       js_declare.tmc
    |       js_map.tmc
    |       js_MI_view.tmc
    |       js_MO_LED.tmc
    |       js_MO_standard.tmc
    |       js_Release.tmc
    |       js_UI_view.tmc
    |       js_UO_LED.tmc
    |       th_declare.tmc
    |       th_map.tmc
    |       th_MO.tmc
    |       util_led.tmc
    |       util_log.tmc
    |       util_usb.tmh

Last edited by ivanwfr; 05-13-2011 at 07:36 PM. Reason: typo
ivanwfr is offline   Reply With Quote
Old 05-06-2011, 12:28 AM   #4
swift's Avatar
Join Date: Dec 2004
Location: Spain
Posts: 447

The force is strong with you, Ivan. You may want to talk with Yoda
swift is offline   Reply With Quote
Old 05-06-2011, 12:37 AM   #5
Join Date: Apr 2011
Location: France - Limours
Posts: 310

Thanks swift, I don't know how I could miss that thread! Reading it right now...
ivanwfr is offline   Reply With Quote
Old 05-06-2011, 12:54 AM   #6
Senior Member
PoleCat's Avatar
Join Date: Dec 2005
Posts: 2,687

Crazy and wonderful stuff!

PoleCat is offline   Reply With Quote
Old 05-11-2011, 06:24 PM   #7
Join Date: Apr 2011
Location: France - Limours
Posts: 310
Default TARGET - Friction Control Slider to adjust SC sensitivity (Slew and mouseStick)

This TARGET script shows how it is possible to adjust Slew Control and trackpoint sensitivity.

Friction Control slider modifies keystrokes down/up time ratio as well as mouse axis curve zoom as appropriate.

Joystick S4 activates SC button press In-layer function (as shift key) to toggle between SC ",./;" default key pulses and mouse pointer mapping.

In each case, sensitivity can be adjusted by the Friction Control slider.

(I can get into more details when/if asked)

After some test, I'm not happy with CPU drain by my REXEC(slewFunctions)...looking for optimization... I crashed twice as the Joystick input was delayed!

But it was good not needing the mouse for Aircraft view handling... I had to invert MOUSE_Y="Camera Vertical View" and MOUSE_Z="Camera Zoom View" to make it feel as you were turning the plane around instead of the camera.
Attached Files
File Type: zip (12.2 KB, 353 views)

Last edited by ivanwfr; 05-15-2011 at 10:51 AM. Reason: script attached!
ivanwfr is offline   Reply With Quote
Old 05-13-2011, 09:38 AM   #8
Senior Member
hreich's Avatar
Join Date: May 2005
Posts: 1,185
Default Question...

Can somebody post detailed info on how to use file so i can have equivalent of the P&P default interactions between Thrustmaster HOTAS and DCS: A-10C.?

Pilot from Croatia
hreich is offline   Reply With Quote
Old 05-13-2011, 12:33 PM   #9
Join Date: Apr 2011
Location: France - Limours
Posts: 310

Well, I didn't bother getting into any detailed procedure on how your're supposed to switch from a default plug & play use of a perfectly working TM Warthog HOTAS as you're supposed to suffer by yourself a little of the "painful" TARGET aproach and I can deduce from your wording that you did not even considered it any bit

If I'm right assuming you're not on the geek side, I would say it's safer to keep away from relying on TM scripting as long as you're not ready to tune the code to your liking. Nearly everything I've put in this script I'm not happy with - yet - but I know I can change any part of it in a matter of seconds without even having to restart the sim! And I'm quite sure you would get more frustration than advantages if you can't do that as easily.

But, would you ask for any "technical" detail, I'm willing to talk about opportunities to improve or adapt all of this... Tell me if you're ready to get your hands dirty with some C'ish coding ...?

Updated first post archive -- Slew keying/mousing tuned by Friction-Control
ivanwfr is offline   Reply With Quote
Old 05-13-2011, 02:18 PM   #10
Senior Member
hreich's Avatar
Join Date: May 2005
Posts: 1,185

Well...what i wanted is a scripted profile, that is same as default TM Warthog DCS A-10c profile, on which I can add my own comands for extrenal views, and such..
So basically a profile that is same as pnp + my own commands added in script editor portion of TM Warthog software...
I have a basic understanding of programing and adding new key presses, tempo functions, 3 layers and shift state...

Pilot from Croatia
hreich is offline   Reply With Quote

hotas, script, target, thrustmaster

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:19 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.