Hardware & Technical Thrustmaster Script vs C

Supposedly, from everything I can find, Thrustmaster scripting language that I use for a Warthog HOTAS is close to real C language and in many cases it is but there are some things that just don't seem to work especially with strings. I've emailed TM support but given I have one ticket that's been ignored for quite a while I don't expect a response from them. Although it's been a while I'm familiar with C (it was one of the first languages I learned).

I simply want to concatenate two strings, s1 and s2. The strcat function is supposed to take s2 and append it to s1 so I do this.

alias s1 ="string1";
alias s2 = "string2";

strcat(&s1, &s2);

printf("....%s\x0a", &s1);

which prints only the word string1 instead of string1string2. The strlen function works but not this one. I've tried various combinations and ways including trying to get the return value (a pointer to s1 supposedly where the supposedly concatenated string is) in an integer and using it.

Any ideas on what I might be doing wrong? I've spent a lot of time looking for documentation (other then the TM stuff) but it there isn't much other than "it's C so you can write C and it will work".

Thanks.
 
It's syntax might be like C but are you sure it handles the memory allocation same?
I mean s1 has space only for "string1". You have to allocate memory for concatenated string.

Maybe this will work:

alias s1 = "string1";
alias s2 = "string2";

alias s1s2 = malloc(srtlen(s1) + strlen(s2));
strcat(&s1s2, &s1);
strcat(&s1s2, &s2);

printf("...%s\x0a", &s1s2);

...

free (s1s2);

My C might be bit rusty so beware of errors...
 
Thrustmaster C

It's syntax might be like C but are you sure it handles the memory allocation same?
I mean s1 has space only for "string1". You have to allocate memory for concatenated string.

Maybe this will work:

alias s1 = "string1";
alias s2 = "string2";

alias s1s2 = malloc(srtlen(s1) + strlen(s2));
strcat(&s1s2, &s1);
strcat(&s1s2, &s2);

printf("...%s\x0a", &s1s2);

...

free (s1s2);

My C might be bit rusty so beware of errors...

malloc, I remember the well! <G>.

I am sure that you are right. I did more experimentation and found that the pointer was null so that means it did not succeed. I also found a reference (after asking the question) at https://linux.die.net/man/3/strcat (I love their manuals) that says the destination must have enough space. In short it's failing because it can't append it and gives me a null pointer to indicate that.

I think I may have to use sprintf so I'll work with that later today and see if that works. If not your solution should work.

Thanks.
 
I did some more testing and the TM Script just doesn't handle this.

The sprintf does not work since you can't define a char *

This does not work either. I think that, like LUA, TM Script is "C like" which means we made enough changes to drive those who know C crazy when they try and use it. I'll do a workaround.

alias t1 = "test1";
alias t2 = " test2";
alias tb = malloc(strlen(&t1) + strlen(&t2) + 5);
strcat(&tb, &t1); < whines about bad alias in this line
strcat(&tb, &t2);
printf("Concatenated string: %s\x0a", &tb);
 
TM Scripts and C

I filed a support request with TM asking questions about this and other Script things and the response I got is that TARGET if free and they don't support it!!! Okay, so basically it's not worth paying the too high price for TM since you basically get big controllers with lots of buttons (yes, it's heavy duty but there are others with lower price points that last longer - some I've had since 2001 and still work). This is good to know for future buying and recommendations to others.
 
This does not work either. I think that, like LUA, TM Script is "C like" which means we made enough changes to drive those who know C crazy when they try and use it. I'll do a workaround.

Maybe it's C like because they couldn't implement proper memory handling (malloc, etc) and left those out.
 
Supposedly, from everything I can find, Thrustmaster scripting language that I use for a Warthog HOTAS is close to real C language and in many cases it is but there are some things that just don't seem to work especially with strings. I've emailed TM support but given I have one ticket that's been ignored for quite a while I don't expect a response from them. Although it's been a while I'm familiar with C (it was one of the first languages I learned).

I simply want to concatenate two strings, s1 and s2. The strcat function is supposed to take s2 and append it to s1 so I do this.

alias s1 ="string1";
alias s2 = "string2";

strcat(&s1, &s2);

printf("....%s\x0a", &s1);

which prints only the word string1 instead of string1string2. The strlen function works but not this one. I've tried various combinations and ways including trying to get the return value (a pointer to s1 supposedly where the supposedly concatenated string is) in an integer and using it.

Any ideas on what I might be doing wrong? I've spent a lot of time looking for documentation (other then the TM stuff) but it there isn't much other than "it's C so you can write C and it will work".

Thanks.

i dont have Thrustmaster at Hand rightnow to test things, but this might help:

&Var and &&Var are all Addresses, not values
an addresses in TARGET is 32bits, 4 bytes
the content of an address is 1 byte.

Eg. String $Var = "Var"
&Var = "V"
&Var + 1 = "a"
&Var + 2 = "r"
&Var + 3 = "0x00" <- term

getmem() will return the content from an address,
or you can specify to return 3 more contents from next 3 addresses.
The content from the first address is the lest significant byte.
TARGET doesn't have any "*pointer" syntax, getmem() is the only
dereference tool.

Strings are Zero Terminated 0x00

Cheers!
 
Last edited:
i dont have Thrustmaster at Hand rightnow to test things, but this might help:

&Var and &&Var are all Addresses, not values
an addresses in TARGET is 32bits, 4 bytes
the content of an address is 1 byte.

Eg. String $Var = "Var"
&Var = "V"
&Var + 1 = "a"
&Var + 2 = "r"
&Var + 3 = "0x00" <- term

getmem() will return the content from an address,
or you can specify to return 3 more contents from next 3 addresses.
The content from the first address is the lest significant byte.
TARGET doesn't have any "*pointer" syntax, getmem() is the only
dereference tool.

Strings are Zero Terminated 0x00

Cheers!

That explains a lot then. I was approaching it from the sense of regular C where if I define *str then I get all the string but if I understand you correctly the & only gives you the first byte and I need getmem(&&Var, 3) to get the entire string up to 4 bytes.

According to the Script manual:

"Reference: & (placed before a variable) – obtain the physical address of the variable
Double Reference: && (placed before a variable) – obtain the physical address of the variable buffer"

so & is the address of the variable and points to the the name of the variable in your example while && returns the address of the buffer which points to the "V", the first character of the variable. Using getmem(&Var, 3) or would I use getmem(&&, 3)?

Do I have that right?

Did you write this post https://forums.robertsspaceindustri...variable-variable-variable-alias-alias-alias? If so thanks.

TM Script is C-Like <G> but not C!

Thank you.
 
I did some testing with this by defining an alias and running code on it so I'm documenting it here for posterity.

alias s1 = "test";
printf("Length of s1: %d\x0a", strlen(&s1));
printf("Test getmem for s1: %d : %c : %c : \x0a", getmem(&&s1, 1 ), getmem(&&s1, 1), getmem(&&s1+1,2));


&s1 is the address of s1 which is the name.
&&s1 points to the value of s1 which in this case is test.

Length prints 4 as it should.
s1 is printed as ASCII code for t, character t, the final prints e as it should.

To get the string I do

printf("Second test: %s \x0a", &&s1);

which gives me test as it should.

It's a round about way but it's C-Like <G>. I think that if you have to work with languages like Lua or scripting that is C-Like you should not know C at all. I programmed an audio system room combiner for a venue in a QSC DSP and Lua was their scripting language. The built in combiner only handled rooms with 2 sections and we had four to eight so I had to use Lua script to create the combiner. Lua is also C-Like but with enough difference that my old habits got in the way.
 
Hey Guys,

I'm probably way off point on what you are trying to achieve. I don't really know C, so much of what is mentioned above goes over my head, and more of a hack at TM scripting tbh, but I did struggle with trying to output a string for some text chat macros I wanted to create. I couldn't find a simple way of doing it (probably for the technical reasons mentioned above), but did find a way to do it in the end (although not very efficient especially if you want to output a longer string) by a CHAIN of single key presses.

Small Example:

This is mapped to a button press on a hat switch.

Code:
mTextPassiveFarewell = CHAIN(PULSE+CommsPanel, D(250), PULSE+QuickCommsPanel, D(),	       [B]// Fly safe CMDR[/B]
			     PULSE+'F', D(50), PULSE+'l', D(15), PULSE+'y', D(15), PULSE+' ', D()  , PULSE+'s', D(15), PULSE+'a', D(15), PULSE+'f', D(15), PULSE+'e', D(15), PULSE+' ', D(),
			     PULSE+'C', D(50), PULSE+'M', D(50), PULSE+'D', D(50), PULSE+'R', D(),
			     PULSE+QuickCommsPanel, D(), UIEscape, D(250), UIEscape);



Just thought I would share in case it is of assistance to anyone.
 
Last edited:
Interesting. Thanks for another approach. There is more than one way to do things in programming!

What started all this was my desire to add statements to functions in my include files for debugging and testing. Printing "I started." and "I ended." was easy but I wanted to output text based on settings passed to the function. For example if a 1 is passed I wanted to put the word "on" in a text string and print it. I had not even thought about outputting text for macros.

Thanks.
 
Nps at all.

For my script, I put most of those printf outputs inline (although that is probably not going to work for all scenarios), but just thinking out loud you could potentially set a variable to a number according to the state you want, then use a debug macro/function with an IF statements to output the according printf string you are after.
 
I put them inline, too. I do use some include files with functions in them. I've just started using my Warthog HOTAS so I've setup a template and am using ED as my first setup from it. Initially because I wanted to get things going I put the If (x) then print this else print this which duplicated a bunch of code.
 
Back
Top Bottom