Jump to content

dmonds

Members
  • Posts

    33
  • Joined

  • Last visited

Personal Information

  • Location
    Auckland, NZ
  1. As the good SGT has suggested...there are some excellent ideas and suggestions within this thread...it is WELL WORTH reading every page! In the meantime, the short answer is no...you can print any variable! printf("My int variable = %d", <int variable>); printf("My String variable = %s", <string variable>); printf("My float variable = %f", <float value>); And it gets better! Hope this helps. dmonds
  2. T-Rudder is normal for TFRPRudder as far as I know. I have one of these and its always been reported that way. dmonds
  3. Too sensible. I'll keep playing with this over time and see what I can learn. Thanks for all your patience in explaining stuff. Cheers dmonds
  4. Hi again...thanks for all that. It makes sense and aligns with how I "thought" it should work. When testing...I wrote a string, using combinations of putc and fwrite. In both cases I wrote a NUL at the end. When reading back...at first I thought I'd nailed it as the printf was printing the string correctly. Then, subsequent, stop/start of the script, and...garbage again at the end of the string. As the strdel seemed to work , I kind of went "too hard, I'll come back to it later". TLDR...I have not seen adding a NUL to a string I am writing in target as doing what it should. Perhaps I did it wrong? I tried fwrite with a string "abcdef\x0" (where string was 7 chars). I tried fwrite with a string "abcdef"...(6 chars) then a putc 0. Both seemed to work at first...then, subsequent runs later....boom....garbage after the string when printf the string...very frustrating. Mind you...only printf exhibited the issue. Things like strcmp etc all worked fine, 100% of the time. Very strange....probably a bug in printf. dmonds
  5. Yeah, sorry...another global which should be local but I've been moving a lot of stuff into and out of my functions. What are the contents of your json file? Maybe it is something in the file you are reading. File I'm reading is a simple, one line json. I have several copies of this which I test my code via a simple copy file on a command line to simulate the program. There is nothing in it which would trip up this function. It is funny my own function to read a configuration file is very similar to yours. Right down to the part where we both figured out we have to add a NULL to the char[0] element of our alias (buf[0]=0 in my version). I take that as a compliment. But I ended up using fgetc(fp) instead of fread() - mostly because I wanted to try character IO on a file instead of taking the easy way out of using fread(). :D You calling me lazy? ;-) But I notice you don't add a NULL to the end of &myJson after you read the line from your file. I assume this somehow doesn't matter for your script? If I remember correctly, I had to add a NULL to the end of &buf because the string functions wouldn't work with it otherwise. See the buf[i+1] = 0 line. Hmmm...the function works but if I printf &myJson ... often get garbage displayed at the end of the string. Hence, the 'strdel' statement. I'm not a programmer, this works, but if there is a 'proper' way to seal my string after the fread, then I'm all ears....are you saying I add a null via a 'strcat' rather than the 'strdel' is better/preferred/more-proper-ish? Anyhoo, regardless of why I needed to run 'fnsReadStatusJson();' before the REXEC ... it now works and I can move onto what I was trying to achieve in the first place. For that, I thank you for your very valuable assistance. Cheers dmonds p.s. no doubt I'll be back with more newbie questions very soon!
  6. /snap...both posted at same time! original post (prior to yours) My eyes are giving up on me...so I'll call it a night and take another look tomorrow. Thanks heaps for helping out...really appreciate it. dmonds
  7. Bizarre!!! If I call fnsReadStatusJson(); before using the REXEC...it works. I do not understand why though. dmonds p.s. using ... ActKey(KEYON+REXEC(3, 5000, "fnsReadStatusJson();", RNOSTOP));
  8. HI @Drakoz (again)... 1) Speak() ... I'm going to have a go at this and see if it works for me in Win10. Voice.exe, I believe, uses the same mshta if I recall, so... 2) REXEC ... still can't get this working. It just hangs the TARGET Script application. Here are the statements I tried... ActKey(KEYON+REXEC(3, 5000, "fnsReadStatusJson();", RNOSTOP)); ...which hangs TARGET script...and... ActKey(KEYON+REXEC(3, 5000, fnsReadStatusJson(), RNOSTOP)); ...which returns "Bad alias in REXEC ( line 415 in target.tmh )" Here's fnsReadStatus() ... int fnsReadStatusJson() { int buf = 512; int myResult; Dim(&myJson, buf); myJson[0] = 0; fp = fopen(&StatusFile, "r"); if (fp) { myResult = fread(&myJson, 1, buf, fp); fclose(fp); if (myResult == 0) { printf("File Read Error: %s\x0a", &StatusFile); } else { strdel(&myJson, myResult-1, buf); // <<< having to do this this is annoying } } else { printf("Status.json file not found.\x0a"); } } Obviously, I have an 'alias Statusfile = "c:\\....file path" ' set correctly and 'char myJson;' declared as global variables ... when I call the function normally, it works perfectly. Any help greatly appreciated. dmonds
  9. Hi @Drakoz, Just read the stuff in the link you included. Interesting stuff, I'll look forward to absorbing properly when I get home tonight. In particular interest was the "Speak()" stuff. I recall that I had trouble getting "spawn" to work in Win 10, so I'm making an assumption that you are using Win7? Anyhoo and just an FYI...I solved my Text-To-Speech requirements by using a free Win32 program called "voice.exe" and using a function with a text string argument parsed to it to dynamically build a "syscmd" to call it. cheers dmonds
  10. Thanks again @Drakoz. My code snippet in my last post is how I was trying to run it. Funnily enough, I use REXEC in my code to in a couple MapKey statements already, and didn't realise REXEC specifically needed a MapKey/ActKey/KeyAxis wrapper. I'll give your suggestion a go this evening when I'm at home again and will let you know. Cheers dmonds
  11. Ok, well thanks @drakoz for proving I'm not a total numpty. My next challenge is REXEC. 1) I have written a function that reads a short, one line json file. 2) I have also written a function to find and read various key values within this file. They work well. 3) I have also found and played with an external C++ program which can also read same file and send me the contents of a specific key whenever it changes (via RegisterGameCallback()). This also works well (but requires the external program to be running whilst the game is running). I was thinking...why not just use REXEC to run the function described in '1)' above every 1-2 seconds and do away with the external C++ program. Except...I can't get this to work. My function name (in a seperate '.tmh' file) is called 'fnReadJson();' My statement is; REXEC(1, 2000, "fnReadJson();", RNOSTOP); This just hangs the Target Script Editor. I've looked for examples and they all deal with a switch/button press and simple ActKey(PULSE+KEYON+'a') type code. Does anyone here know how I can call my function using REXEC (or any other method) and have it loop indefinitely in the background? Thanks dmonds
  12. Help to get position of substring in TARGET SCRIPT Hiya, I'm working my way through the string manipulation functions available (listed in sys.tmh). I am stumbling on the following function. int strstr(alias string, alias substring){} // returns substring position, or -1 of not found I cannot seem to get this to work. It always returns a '0'. sample code... alias string1 = "This is a test"; alias string2 = "is"; int pos; pos = strstr(&string1, &string2); printf("pos = %d\x0a", pos); Can anyone here advise what I'm doing wrong and how to get this working? Or, heaven forbid, I found a bug in this function! dmonds
  13. Not too sure what you are trying to achieve here. But, you can simply include “file.tmc” in your main script file. Otherwise, if what you are looking to do is remap one or more keys, you can do this from within a function/routine, then when you want to switch , just call the function. Dmonds
  14. Hi guys, Has anyone had experience with the TARGET system() function on Windows 10? I've used this method to grab the Time of Day and add to console or log file messages as follows... int TOD; system("time /T > c:\\tod.txt"); fp = fopen("c:\\tod.txt", "r"); if (fp) { fread(TOD, 1, 5, fp); fclose(fp); } I'm really just interested in any examples of working script code which uses system() under Win10. Cheers dmonds
×
×
  • Create New...