Previous Thread
Next Thread
Print Thread
Rate This Thread
Hop To
#4170297 - 09/17/15 11:20 PM Are any of these things possible?  
Joined: Sep 2015
Posts: 2
Avder Offline
Junior Member
Avder  Offline
Junior Member

Joined: Sep 2015
Posts: 2
Hey there, I just joined this forum because this is one of the few places on the internet where TARGET scripting is discussed in-depth and I'm looking to do some stuff with one that involves stuff not covered anywhere in the manual.

I'm in the process of building a rather complex script to perform actions on my T16000M based on a sequence of hat directions I've entered and I'd like a little help.

First of all, is there any way to get a REXEC statement to auto-execute when the script starts? Right now the only way I have to get things rolling is to bind it to a button and then once it's going, the script gives that button back its intended binds during its first runthrough.

Are there any internal variables that TARGET itself uses to monitor what layer and shiftstate the controller is operating under? I'd like to add conditional processing based on mode and shiftstate and I'm wondering if there's an easier way to do it besides watching the shift button and mode toggle buttons and storing flags. The way my script works pretty much excludes the use of MAPKEYIOUMD statements as I'm generating button presses completely through code.

Whats the most reliable way to take a string that I set up in a define statement and pass that through a few variables and have it understood later on to be the exact same thing as what I wrote in the define statement? For instance, based on conditions in my script at some point I'll want to send a DXHATUPRIGHT so I have that in a define statemment. But the only way to finally send that command is to execute a hardcoded ActKey statement that points directly at the define. My code could be a LOT be simpler if I could pass the defined command from variable to variable but I can't figure out how to do that.

And finally, is there any way in TARGET to generate a timer that increments in time with the system clock? Something like how the autohotkey A_ClockTick command returns the system uptime in milliseconds.

Thanks for any help!

Inline advert (2nd and 3rd post)

#4171058 - 09/20/15 04:17 AM Re: Are any of these things possible? [Re: Avder]  
Joined: Mar 2007
Posts: 483
Aullido Offline
Member
Aullido  Offline
Member

Joined: Mar 2007
Posts: 483
Originally Posted By: Avder
Hey there, I just joined this forum because this is one of the few places on the internet where TARGET scripting is discussed in-depth and I'm looking to do some stuff with one that involves stuff not covered anywhere in the manual.

I'm in the process of building a rather complex script to perform actions on my T16000M based on a sequence of hat directions I've entered and I'd like a little help.

[quote=Avder]First of all, is there any way to get a REXEC statement to auto-execute when the script starts? Right now the only way I have to get things rolling is to bind it to a button and then once it's going, the script gives that button back its intended binds during its first runthrough.


Try to use a switch. They are generally detected at startup.

Originally Posted By: Avder
Are there any internal variables that TARGET itself uses to monitor what layer and shiftstate the controller is operating under? I'd like to add conditional processing based on mode and shiftstate and I'm wondering if there's an easier way to do it besides watching the shift button and mode toggle buttons and storing flags. The way my script works pretty much excludes the use of MAPKEYIOUMD statements as I'm generating button presses completely through code.


Well there is a way but is not very reliable. I have a Warthog and for the Throttle you can read the buttons and switches states using Throttle[Button/Switch Position]. As example:

if (Throttle[APUON])
{
MakeKey(&Throttle,EACON,'a');
}

The problem is that for switches is not very reliable. I am sure there is a similar array for the T16000M.

Originally Posted By: Avder
Whats the most reliable way to take a string that I set up in a define statement and pass that through a few variables and have it understood later on to be the exact same thing as what I wrote in the define statement? For instance, based on conditions in my script at some point I'll want to send a DXHATUPRIGHT so I have that in a define statemment. But the only way to finally send that command is to execute a hardcoded ActKey statement that points directly at the define. My code could be a LOT be simpler if I could pass the defined command from variable to variable but I can't figure out how to do that.


I am not sure what do you intent.
Strings are not good parameters.
A define is just text that is replaced at compiler time, good for constants values.

Send me a PM. I will gladly help you.

Originally Posted By: Avder
And finally, is there any way in TARGET to generate a timer that increments in time with the system clock? Something like how the autohotkey A_ClockTick command returns the system uptime in milliseconds.

Thanks for any help!


TARGET is capable of running external code but I am sure there is better ways to it. What do you want? Check the DeferCall() and D() functions. At last resort you can increment a variable on a while cycle.

#4171308 - 09/21/15 12:01 AM Re: Are any of these things possible? [Re: Avder]  
Joined: Sep 2015
Posts: 2
Avder Offline
Junior Member
Avder  Offline
Junior Member

Joined: Sep 2015
Posts: 2
Thanks for replying, I was starting to wonder if anyone would.

I actually discovered a solution to everything except the timer on my own over the last few days.

The easiest was why I was unable to send commands properly from variable to variable. I was using char when I should have been using int. That all works fine now.

For the detection of what layer TARGET is operating under, I found I just need to read TARGET's internal layers_sw[] variable at indexes 2, 5, and 8 to get on or off bits for the shift, up, and down layers respectively.

Here's what my code looks like for reading the layer state:
Code:
int ReadIOUMD() 
	{
	if (layer_sw[2] == 0)
		{
		ShiftState = 'o';
		}
	else
		{
		ShiftState = 'i';
		}
	if ((layer_sw[5] == 1) & (layer_sw[8] == 0))
		{
		LayerMode = 'u';
		}
	else if ((layer_sw[5] == 0) & (layer_sw[8] == 1))
		{
		LayerMode = 'd';
		}
	else
		{
		LayerMode = 'm';
		}
			
	}


As for the timer, well I've got an improvised one like you said, incrementing a variable over time. I call a function to do this at the very start of my rexec that adds the loop time to a variable each time through.
Code:
int IncrementTimer()
	{
	ScriptTimer=(ScriptTimer+(REXECLength/1000));
	}


ScriptTimer and REXECLength are both floats. Also it seems TARGET doesn't have very good floating point precision. Right now I've got my REXEC running every 25ms, so ScriptTimer should always be a multiple of 0.025, but it starts going off by 0.00001 after a couple of seconds. It's still accurate enough for what I use it for later in the script, but it just irks me.

What I had been hoping for was some concrete way to generate a timestamp based on the system clock like in Autohotkey.
In autohotkey I can do this:

MyTimer := A_TickCount

which sets MyTimer to the current system uptime in ms. And then later I can just compare MyTimer to the current value of
A_TickCount and I've got a timer based on the system clock. I do the comparison in my TARGET script the same way, just using that manually incremented timer. I had been hoping to find some internal target variable that does the same thing since d() and defercall seem like they would need one and just piggyback on it the same way I'm piggybacking on layer_sw. But this makeshift way seems to function well enough.


As for getting a rexec to run by itself...

You said use a switch, are you talking about a physical button on the stick? Well that's basically what I had been doing.

Previously I had set this bind somewhere in main():
MapKey(&T16000, TS1, REXEC(0, REXECLength, "MyScript();", RNOSTOP));

And then once the script starts it would hand the trigger back its default function the first time it runs:
MapKey(&T16000, TS1, DX1);

But I discovered that I can trigger a rexec using an ActKey:
ActKey(KEYON+PULSE+REXEC(0, REXECLength, "MyScript();", RNOSTOP));

I would not be opposed to suggestions for a better way to do things if you know a different way to and see a problem with anything I'm doing here.

Last edited by Avder; 09/21/15 12:02 AM.

Moderated by  RacerGT 

Quick Search
Recent Articles
Support SimHQ

If you shop on Amazon use this Amazon link to support SimHQ
.
Social


Recent Topics
Actors portraying British Prime Ministers
by Tarnsman. 04/24/24 01:11 AM
Roy Cross is 100 Years Old
by F4UDash4. 04/23/24 11:22 AM
Actors portraying US Presidents
by PanzerMeyer. 04/19/24 12:19 PM
Dickey Betts was 80
by Rick_Rawlings. 04/19/24 01:11 AM
Exodus
by RedOneAlpha. 04/18/24 05:46 PM
Grumman Wildcat unique landing gear
by Coot. 04/17/24 03:54 PM
Peter Higgs was 94
by Rick_Rawlings. 04/17/24 12:28 AM
Whitey Herzog was 92
by F4UDash4. 04/16/24 04:41 PM
Copyright 1997-2016, SimHQ Inc. All Rights Reserved.

Powered by UBB.threads™ PHP Forum Software 7.6.0