Author Topic: reading ship type from stored file and running a script set up for that ship typ  (Read 7529 times)

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
I have created a file that shows the current ship type I am using in Elite Dangerous. I can't figure out how to retrieve that info and have it run a script that is set up for that type of ship.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
You can use the "Value from file/URI" option of the "Set a Text Value" action to read the contents of a text file into a VoiceAttack variable, which you can then use in conditions to choose which actions are executed for the given type.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Thanks you

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
the problem I am stuck at, is that file has 4 entries how do I get va to read say first word on line 4 and I am still confused as to how to set the variable for the 8 ships I use

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
You'll have to use a combination of the "{TXTSUBSTR:}", {TXTPOS:}, and/or "{TXTLASTPOS:}" tokens to select the appropriate line/word (the "{NEWLINE}" token can be used to find the start/end of a line).

If you have control over what's being written to that text file, it'd be a whole lot simpler if you only write exactly what you need (E.G. the current ship type as the first and only line) to it.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
I'm not sure how to write the command and use the 8 ship variable in command. Are you aware of an example I can use to maybe get me started?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
An example of what exactly?

Reading the first word of the fourth line of a text file could look like this:
Code: [Select]
Set Text [~t] to [C:\text.txt]
Set integer [~i] value to 0
Start Loop : Repeat 3 Times
    Set integer [~i] value to the converted value of {TXTPOS:"{NEWLINE}":~t:{EXP: {INT:~i} + 2}}
End Loop
Write [Blue] '"{TXTSUBSTR:~t:{EXP: {INT:~i} + {TXTLEN:"{NEWLINE}"}}:{EXP: ({TXTPOS:" ":~t:~i} - {INT:~i}) - {TXTLEN:"{NEWLINE}"}}}"' to log

But, again, if you have control over what is written to the text file, why have the data you need on the fourth line rather than the first?

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
I do. it was produced in autohotkey so should be able to eliminate the other entries. Is there a difference for reading say line 4 vs reading first word in line 4?
The example that I was referring to was an example of how to write the command to retrieved the text from the file

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Am I on the right track or should I just thrown in the towel on this idea

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
I don't know which values you're trying to store aside from which ship you're currently using, but for the latter could you not use something like
Code: [Select]
Set Text [ship-type] to [C:\Status.log]
Begin Text Compare : [ship-type] Equals 'cutter'
    Write [Blue] 'Do things for cutter here' to log
Else If Text Compare : [ship-type] Equals 'anaconda'
    Write [Blue] 'Do things for anaconda here' to log
Else If Text Compare : [ship-type] Equals 'corvette'
    Write [Blue] 'Do things for corvette here' to log
//etc...
End Condition
?
without having to involve any other variables or types of variables to determine which ship you're using.

You have the name of the ship in a text value, which is going to be the best choice in most cases to keep track of that state, rather than having to remember which number happens to match which ship.

The only reason to go with a numeric value in a context like this is if you need to iterate through values (I.E. adding or subtracting from the value to make a relative change, rather than setting an absolute value directly).

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Oh ok that make sense based on my limit experience I was using an existing command to do what I wanted.
Thanks

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Clearly I did something wrong. I altered the text file so that the ship type is on line one, but it would not compare text unless I eliminated all the other text.
I also tried to combine the example you gave for reading line 4 in the text file that didn't work either, clearly I don't understand how to combine them.
I do want to  thank you for all your assistance, and I at least understand how to compare text in a file with only one word entry. I at least made one baby half step forward.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
If there is other text in the file, the compare will indeed fail as E.G. the literal text "cutter" will not equal the literal text "cutter and more".

However, assuming you only have a single ship name in the text file (I.E. the other data will not randomly include another ship name, even as part of another word), you can use the "Contains" operator instead of the "Equals" operator.

E.G.
Code: [Select]
Begin Text Compare : [ship-type] Contains 'cutter'

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Thanks again that solved the issue I was having with the other text in the file. Fortunately it's just 4 lines of single text and numbers, and the "contain" sorted them out. I know this is a temporary fix if I want to pull other things from the list, sentences and numbers as well.
Its to bad that examples like this don't exist in the manual but I am guessing that would make for a lot of work and a manual hundreds of pages long and it would still only cover some of the simple things people ask for or about.