Author Topic: variable from txt-file  (Read 6196 times)

Coverdale

  • Newbie
  • *
  • Posts: 7
variable from txt-file
« on: February 10, 2021, 10:43:49 AM »
Hello,

I write variable data from a game into a TXT file, which I read in again as a variable in VoiceAttack with "set text [COM_1] to [D: \ ..... \ COM_1.txt]". These variables change at several intervals. But since I need several files, I've written a TXT file for each variable so far.
Now my question: Is there a way to read several variables directly from one TXT file?

Many greetings,
Coverdale

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: variable from txt-file
« Reply #1 on: February 10, 2021, 01:32:44 PM »
Not directly, but you can get the contents of a text file, and parse those to split them into separate values (E.G. one per line), then store those values in their own variables.

The "{TXTSUBSTR:" and "{TXTPOS:}" tokens can be used for that, combined with a loop and some variables, or you could use an inline function to be able to utilize the String.Split() method.


If you can modify the way this game data is handled, you could also try having it run VoiceAttack with the "-command" and "-PassedText" arguments (possible combined with another argument if you're passing a different variable type), to store the data somewhat more directly.


All of these are advanced features. Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains more information.

These topics may also be of use:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

Coverdale

  • Newbie
  • *
  • Posts: 7
Re: variable from txt-file
« Reply #2 on: February 11, 2021, 08:55:17 AM »
Thanks Pfeil for the quick answer.

Since I've been doing this, I've often had the problem that VoiceAttack no longer responds and is terminated. I suspect that about 13 files are being written by the game and 13 files are being read in by VoiceAttack at the same time. Could that be the problem? That's why I thought about doing everything with just 1 file at a time. Could that be a solution?

Kind regards, Coverdale

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: variable from txt-file
« Reply #3 on: February 11, 2021, 02:22:11 PM »
Reading can fail if a file is locked for writing, though normally that type of exception should be caught and handled gracefully; perhaps the quantity and/or frequency has something to do with it.

That is also one of the reasons why using a file as an intermediary for exchanging data is not ideal.
If you can send the data directly, using a second instance of VoiceAttack with the correct command line arguments/parameters, as mentioned, or another mechanism, E.G. sending the data over UDP to an inline function or plugin on the VoiceAttack side, would be more efficient.

Coverdale

  • Newbie
  • *
  • Posts: 7
Re: variable from txt-file
« Reply #4 on: February 11, 2021, 05:40:04 PM »
Hello Pfeil and thank you for your help.
As I'm not a programmer, I don't know how to access the game's data directly. In this game I have the possibility to read the data from Lua-Script. I can reduce the data to approx. 6 values and will try it with your suggestion via {TXTPOS: ...}.

Kind regards, Coverdale