Discussion New Journal and AHK

Just a quick question about the new journal and extracting data from it: I used to use one of the third party tools to dump play info into a JSON file and extract the players current ship from it using an AHK script - how easy is that to do now with the new journal? I seem to recall the old method had everything tagged quite nicely so it was easy to pull the info and the file always had the same name I assume this may have changed? I would like to update my app as it has a reliance on Python to get the info from the mobile app - obviously it would benifitial to remove this dependency if possible.
 
Anyone using AHK and the JSON.ahk lib? I can't get it to parse anything from the journal....Some pointers would really be appreciated for the new file.

In the past I used EDCE to pull info from the Mobile App, it was outputted as a JSON file called: Last.Json. I then used the following AHK / JSON.ahk script to pull the commanders current ship from that file (Root.Ship.Name):

FileRead, JSONtext, %A_ScriptDir%/last.json
API_READ := JSON.Decode(JSONtext)
CShip := API_READ.ship.name

Now with the new journal the same will not work, even with the new categories such as 'ShipType' which I can clearly see in my Journal file under Root.ShipType

JournalDir = C:\Users\XXXXX\Downloads\Journals\
Pattern = %JournalDir%Journal*
Loop, %Pattern%, 1
FileList = %FileList%%A_LoopFileTimeCreated%`t%A_LoopFileName%`n
Sort, FileList
Loop, parse, FileList, `n
{
StringSplit, FileItem, A_LoopField, %A_Tab%
}
JournalFile = %FileItem2%
FullJournal = %JournalDir%%JournalFile%
FileRead, JSONtext,%FullJournal%
API_READ := JSON.Decode(JSONtext)
CShip := API_READ.ShipType
Msgbox, %CShip%


Where am I going wrong?
 
Last edited:
The journal-file is in line-delimited JSON format. This means that each line of the file is a valid JSON-object but not the whole file.

You have to read and decode the journal-file line by line otherwise every JSON parser will report an error.

Thanks - not sure how I over looked that! I now have a test script which outputs the current ship after a player changes ship, which is what I set out to achieve. I have a bit more work to do in order to fit this code (or a variation there of) into my main script but its looking very promising now. Here is what I came up with, basically it finds the latest journal file, the number of lines within it, and extracts the players ship type from the last line in the journal, or if it's not in the last line, works backwards until the value is found - its likely useless to anyone else but you never know it might help someone having a similar issue.


Code:
#include JSON.ahk
LoopNum = 1
JournalDir = C:\Users\%A_UserName%\Saved Games\Frontier Developments\Elite Dangerous\
Pattern = %JournalDir%Journal*
Loop, %Pattern%, 1
FileList = %FileList%%A_LoopFileTimeCreated%`t%A_LoopFileName%`n
Sort, FileList
Loop, parse, FileList, `n
    {
     StringSplit, FileItem, A_LoopField, %A_Tab%
    }
JournalFile = %FileItem2%
FullJournal = %JournalDir%%JournalFile%                                                     ;Path to newest Journal File.
FileRead, JSONtext, %FullJournal%
Loop, Parse, JSONtext, `n, `r
JSONLines :=  A_Index
Lastline := JSONLines - 1                                                                  
FileReadLine, lastjson, %FullJournal%, %Lastline%
JSON_READ := JSON.Decode(lastjson)
CShip := JSON_READ.Ship                                                                           ;Displays last Ship in Journal File.
if CShip = 
{
Loop, %Lastline%                                                                           ;Loops number of lines in Journal File
    {
	 Lastline2 := Lastline -LoopNum
	 FileReadLine, lastjson, %FullJournal%, %Lastline2%
	 JSON_READ := JSON.Decode(lastjson)
	 CShip := JSON_READ.Ship
	 LoopNum++
	 If CShip >
        {	 
	     break
	    }
	}	
MSGBox, Ship was not in last line but is a %CShip% 
}
Else 
MSGBox, The ship was in last line and is a %CShip%
 
Last edited:
Back
Top Bottom