Jump to content

Recommended Posts

Posted (edited)

Trying to write a target script to emulate a rotary switch in game. I can make the switch advance and reverse direction, but having trouble getting my head around a way to have it stop advancing at the last position.

Any help appreciated.

 

 

A little more explanation of what I want to do.

In DCS, there are plenty of examples of rotary switches that don't have a Clockwise or Counter Clockwise keyboard equivalent. The AAP in the A10C, for example, has two rotary switches that lack this function. They have the keyboard commands for each position. That's 7 commands for two switches when a simple CW and CCW for each, would do very nicely.

 

 

I play in VR ,and I have a condition that makes it difficult to turn my head and look down at certain angles, let alone to the rear and down for those pesky ones in the back. Any way. Mapping those to a hat in TARGET is a lot easier than trying to use my head to put the cursor on the switch, or crashing the plane trying find the keys on the board.

 

 

With this code I want the rotary to act as it would as if I was trying to turn it by hand, and stop turning when I reach the last position. If I try to keep going beyond the last position I want the button to do nothing, until I go the other direction.

 

 

There may or not be a way to edit the game files, but I loath to touch those. I'm playing OB and I just don't want the headache with updates.

 

 

I did this before for the Viggen, but I can't find the code anywhere. I believe there was a bizarre gardening accident.

 

 

My .tmc

include "target.tmh"
include "Rotary_Switch_Macro.ttm"

int Rotary_Pos, index; //rotary modes list function & index

int main()
{
if(Init(&EventHandle)) return 1;

       Rotary_Pos = SEQ(red,
                       white,
                       blue);

//Coolie Switch is used for Modes selection---------------

MapKey(&Throttle, CSU, EXEC("index = (index+1)%3; ActKey(KEYON+PULSE+X(Rotary_Pos, index));")); // forward
MapKey(&Throttle, CSD,EXEC("index = (index+2)%3; ActKey(KEYON+PULSE+X(Rotary_Pos, index));")); // 2 is 3-1= backward

}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
}

Macro File

define    red        'r'
define    white    'w'
define    blue    'b'

 

 

Solution:

 

My .tmc

include "target.tmh"
include "TD_Functions.tmh"

int counter = 1;
int listmode, index;

//program startup
int main()
{
   if(Init(&EventHandle)) return 1; // declare the event handler, return on error
   listmode = SEQ('a','b','c','d');    
   //add initialization code here
   MapKey(&Joystick, H1R, EXEC("ClockWise();"));
   MapKey(&Joystick, H1L, EXEC("CounterClockWise();"));
}

//event handler
int EventHandle(int type, alias o, int x)
{
   DefaultMapping(&o, x);
   
   //add event handling code here
}

My .tmh

//***************************************************
//  ClockWise and CounterClockWise functions

int    ClockWise()    {
   if (counter<4) {
       index = (index + 1)%4;
       counter = (counter + 1);
       ActKey(PULSE+KEYON+X(listmode,index));
       printf("CW \xa");
   }
   else if (counter >= 4)    {
       ActKey(PULSE+KEYON+0);
       printf("CW end \xa");
   
   }
}    

int    CounterClockWise()    {
   if (counter>1) {
       index = (index + 3)%4;
       counter = (counter - 1);
       ActKey(PULSE+KEYON+X(listmode,index));
       printf("CCW \xa");
   }
   else if (counter <= 1)    {
       ActKey(PULSE+KEYON+0);
       printf("CCW end \xa");
   
   }
}
//****************************************************

 

Edited by SGT Coyle
Solved

Night Ops in the Harrier

IYAOYAS


 
Posted

So I tried the following code as a test. It compiles, runs, adn doesn't throw an error when I actuate button, but doesn't produce any output in the "tester".

include "target.tmh"
include "Rotary_Switch_Macro.ttm"

int Rotary_Pos, index; //rotary modes list function & index
int count=1; // init with value=1
int main()
{
if(Init(&EventHandle)) return 1;

       Rotary_Pos = SEQ(red,
                       white,
                       blue);

//Coolie switch is used for Modes selection---------------


if (count < 3)
{
MapKey(&Joystick, CSU, EXEC("index=(index+1)%3;ActKey(PULSE+KEYON+Rotary_Pos,index);"));
}
else
{
MapKey(&Throttle, CSU, 0);
}                             

}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
}

Night Ops in the Harrier

IYAOYAS


 
Posted

I will try to see if i can help you out when i get home in the next days. Not quite sure what you are trying to do, though, and why you use pure scripting.

 

Cheers

[sIGPIC][/sIGPIC]

Win10 64, Asus Maximus VIII Formula, i5 6600K, Geforce 980 GTX Ti, 32 GB Ram, Samsung EVO SSD.

Posted (edited)

In the meantime, you can search for a thread that called something like advanced scripting or something like that. there might be something in there. A couple of years old by now.

 

Found it:

https://forums.eagle.ru/showthread.php?t=73271

Edited by Svend_Dellepude

[sIGPIC][/sIGPIC]

Win10 64, Asus Maximus VIII Formula, i5 6600K, Geforce 980 GTX Ti, 32 GB Ram, Samsung EVO SSD.

Posted (edited)

Pros: Works

Cons: Not very elegant

 

 

[color=#1e90ff][b]include[/b][/color] [color=#a52a2a]"target.tmh"[/color]

[color=#1e90ff][b]int[/b][/color] counter = [color=#ffffff]1[/color];

[color=#32cd32]//program startup[/color]
[color=#1e90ff][b]int[/b][/color] main()
{
   [color=#1e90ff][b]if[/b][/color][color=#ffffff]([/color]Init(&EventHandle)) [color=#1e90ff][b]return[/b][/color] [color=#ffffff]1[/color]; [color=#32cd32]// declare the event handler, return on error[/color]
   
   [color=#32cd32]//add initialization code here[/color]
   
   [color=#32cd32]// China Hat [/color]
   MapKey(&Throttle, CHF, EXEC([color=#a52a2a]"Forward();"[/color]) );
   MapKey(&Throttle, CHB, EXEC([color=#a52a2a]"Backward();"[/color]) );
       
}


[color=#1e90ff][b]int[/b][/color] Forward() {  
    [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]4[/color]) {
       [color=#32cd32]//delete me for no action
[/color]         ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F4);
   }
   [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]3[/color]) {
       counter = counter + [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F4);
   }    
   [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]2[/color]) {
       counter = counter + [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F3);
   }
   [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]1[/color]) {
       counter = counter + [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F2);
   }
}

[color=#1e90ff][b]int[/b][/color] Backward() {  
   [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]4[/color]) {
       counter = counter - [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F3);
   }
   [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]3[/color]) {
       counter = counter - [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F2);
   }    
   [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]2[/color]) {
       counter = counter - [color=#ffffff]1[/color];
       ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F1);
   }
    [color=#1e90ff][b]else[/b][/color] [color=#1e90ff][b]if[/b][/color] (counter == [color=#ffffff]1[/color]) {
       [color=#32cd32]//delete me for no action[/color]
        ActKey[color=#ffffff]([/color]PULSE[color=#ffffff]+[/color]KEYON[color=#ffffff]+[/color]F1);
   }
}

[color=#32cd32]//event handler[/color]
[color=#1e90ff][b]int[/b][/color] EventHandle[color=#ffffff]([/color][color=#1e90ff][b]int[/b][/color] type, [color=#1e90ff][b]alias[/b][/color] o, [color=#1e90ff][b]int[/b][/color] x)
{
   DefaultMapping(&o, x);
   
   [color=#32cd32]//add event handling code here[/color]
}

Edited by Thermal
  • 3 months later...
Posted (edited)

Got It!!!

After almost four months of trial and error, furious googling, and feelings of disgust mixed with admiration of what some of you people do. I got it.

 

 

.tmc

include "target.tmh"
include "TD_Functions.tmh"

int counter = 1;
int listmode, index;

//program startup
int main()
{
   if(Init(&EventHandle)) return 1; // declare the event handler, return on error
   listmode = SEQ('a','b','c','d');    
   //add initialization code here
   MapKey(&Joystick, H1R, EXEC("ClockWise();"));
   MapKey(&Joystick, H1L, EXEC("CounterClockWise();"));
}

//event handler
int EventHandle(int type, alias o, int x)
{
   DefaultMapping(&o, x);
   
   //add event handling code here
 }

.tmh


//***************************************************
//  ClockWise and CounterClockWise functions

int    ClockWise()    {
   if (counter<4) {
       index = (index + 1)%4;
       counter = (counter + 1);
       ActKey(PULSE+KEYON+X(listmode,index));
       printf("CW \xa");
   }
   else if (counter >= 4)    {
       ActKey(PULSE+KEYON+0);
       printf("CW end \xa");
   
   }
}    

int    CounterClockWise()    {
   if (counter>1) {
       index = (index + 3)%4;
       counter = (counter - 1);
       ActKey(PULSE+KEYON+X(listmode,index));
       printf("CCW \xa");
   }
   else if (counter <= 1)    {
       ActKey(PULSE+KEYON+0);
       printf("CCW end \xa");
   
   }
}
//****************************************************

Thanks,

Thermal. Your solution worked fine, but I knew there was another way. Appreciate you help.

Edited by SGT Coyle

Night Ops in the Harrier

IYAOYAS


 
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...