Author Topic: Elite dangerous flags values total  (Read 5562 times)

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Elite dangerous flags values total
« on: April 19, 2020, 08:52:43 AM »
I am trying to figure out a way to separate the flag values that are assigned in the status log of the player journal.
Flags:   
Bit    Value       Hex       Meaning

0      1       0000 0001    Docked, (on a landing pad)
1   2       0000 0002    Landed, (on planet surface)
2   4       0000 0004   Landing Gear Down
3    8       0000 0008    Shields Up
4    16       0000 0010    Supercruise
5    32       0000 0020    FlightAssist Off
6    64       0000 0040    Hardpoints Deployed
7    128       0000 0080    In Wing
8    256       0000 0100    LightsOn
9    512       0000 0200    Cargo Scoop Deployed
10    1024    0000 0400    Silent Running,
11    2048       0000 0800    Scooping Fuel
12    4096       0000 1000    Srv Handbrake
13    8192       0000 2000    Srv using Turret view
14    16384      0000 4000    Srv Turret retracted (close to ship)
15    32768       0000 8000    Srv DriveAssist
16   65536       0001 0000    Fsd MassLocked
17    131072      0002 0000    Fsd Charging
18    262144       0004 0000    Fsd Cooldown
19    524288       0008 0000    Low Fuel ( < 25% )
20    1048576            0010 0000    Over Heating ( > 100% )
21    2097152           0020 0000   Has Lat Long
22    4194304            0040 0000    IsInDanger
23    8388608            0080 0000    Being Interdicted
24    16777216   0100 0000    In MainShip
25    33554432    0200 0000    In Fighter
26    67108864   0400 0000    In SRV
27    134217728   0800 0000    Hud in Analysis mode
28    268435456   1000 0000    Night Vision
29   536870912   2000 0000    Altitude from Average radius
30    1073741824    4000 0000    fsdJump
31    2147483648    8000 0000    srvHighBeam

 Flags":16842765 total  how can the represented values be separated to determine which meanings are included
The included flags in the total =  24, 16, 3, 2, 0
« Last Edit: November 14, 2020, 07:46:58 PM by Incurable-Rash »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #1 on: April 19, 2020, 10:05:34 AM »
This is advanced subject matter, that is going to require you to have an understanding of the binary numeral system (the hexadecimal system is also shown in your example, but that's not as relevant to the practical solution), and of C# (I'm not saying you couldn't do this with VoiceAttack actions, but it's not going to make it any simpler to reinvent the wheel like that).

This example will print the active flags to the log, preceded by "Docked" if that flag is active:
Code: [Select]
using System;

public class VAInline
{
[Flags]
enum status : uint
{
Docked = 1,
Landed = 2,
LandingGearDown = 4,
ShieldsUp = 8,
SuperCruise = 16,
FlightAssistOff = 32,
HardpointsDeployed = 64,
InWing = 128,
LightsOn = 256,
CargoScoopDeployed = 512,
SilentRunning = 1024,
ScoopingFuel = 2048,
SrvHandbrake = 4096,
SrvUsingTurretView = 8192,
SrvTurretRetracted = 16384,
SrvDriveAssist = 32768,
FsdMassLocked = 65536,
FsdCharging = 131072,
FsdCooldown = 262144,
LowFuel = 524288,
OverHeating = 1048576,
HasLatLong = 2097152,
IsInDanger = 4194304,
BeingInterdicted = 8388608,
InMainShip = 16777216,
InFighter = 33554432,
InSrv = 67108864,
HudInAnalysisMode = 134217728,
NightVision = 268435456,
AltitudeFromAverageRadius = 536870912,
FsdJump = 1073741824,
SrvHighBeam = 2147483648
}

public void main()
{
status flags = (status)16842765;

if (flags.HasFlag(status.Docked))
{
VA.WriteToLog("Docked");
}
VA.WriteToLog("Flags: " + flags);
}
}
« Last Edit: May 18, 2020, 08:22:28 AM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Elite dangerous flags values total
« Reply #2 on: April 19, 2020, 10:31:51 AM »
Holy mackerel - this is fantastic!

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #3 on: April 19, 2020, 10:45:18 AM »
Yep I was thinking this was way way way above my pay grade, and learning. I think I am wandering to deep water here with no ability to swim without help. Thanks.

I am not sure you are saying it, but the total changes with what is going on in the game and it is only represented as a total of the values in the logs. the other numbers are not used if I understand how this works from the manual. So separating the individual values from the total is what is needed.
Sorry if I was not clear or I am not understanding what you provided.
and once again thanks for even providing the information and example.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #4 on: April 19, 2020, 11:33:18 AM »
You do need all the numbers for this as the given value can be any combination of them; That is exactly how this type of enumeration works (the inline function basically reverses the process that the game uses to encode the information in the first place).

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #5 on: April 21, 2020, 11:13:36 AM »
Thank you for the information and the code. As I said this is way above my knowledge level. I have read the inline function section and plugin section, and although it kind of makes sense, it does not help me. I almost need a "go to the freezer and get the cheese", kind of a description of what to do with it, how to uses it and where to put it. I know I am asking a lot here so if this is beyond what you are willing/want, to do I understand. I will just move on to something else within my abilities.
Either way thanks for all that you folks do for us.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #6 on: April 21, 2020, 11:25:14 AM »
What can you utilize? I can have the inline function set boolean variables, so you can check those instead, for example.

The list of flags that are active can also be set to a variable, so you can check whether the list of active flags contains a given flag, if that's more feasible for you to work with.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #7 on: April 21, 2020, 12:44:25 PM »
In a perfect world I would use what you provided but I think I would have to have someone hold my hand to do that and that is not practical. I think I can work with variable, never used boolean but all of it I need to learn if I want to make any head way.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #8 on: April 21, 2020, 12:58:44 PM »
Having the flags in a text variable might be the simplest to work with, so you can check for the presence of any specific flag, E.G.
Code: [Select]
Set text [statusFlags] to '16842765'
Inline C# Function: Elite:Dangerous flags to text, wait until execution finishes
Write [Blue] '{TXT:statusFlags}' to log
Begin Text Compare : [statusFlags] Contains 'SilentRunning'
    Write [Blue] 'Silent running is active' to log
Else
    Write [Blue] 'Silent running is not active' to log
End Condition

Where "Elite:Dangerous flags to text" contains:
Code: [Select]
using System;

public class VAInline
{
[Flags]
enum status : uint
{
Docked = 1,
Landed = 2,
LandingGearDown = 4,
ShieldsUp = 8,
SuperCruise = 16,
FlightAssistOff = 32,
HardpointsDeployed = 64,
InWing = 128,
LightsOn = 256,
CargoScoopDeployed = 512,
SilentRunning = 1024,
ScoopingFuel = 2048,
SrvHandbrake = 4096,
SrvUsingTurretView = 8192,
SrvTurretRetracted = 16384,
SrvDriveAssist = 32768,
FsdMassLocked = 65536,
FsdCharging = 131072,
FsdCooldown = 262144,
LowFuel = 524288,
OverHeating = 1048576,
HasLatLong = 2097152,
IsInDanger = 4194304,
BeingInterdicted = 8388608,
InMainShip = 16777216,
InFighter = 33554432,
InSrv = 67108864,
HudInAnalysisMode = 134217728,
NightVision = 268435456,
AltitudeFromAverageRadius = 536870912,
FsdJump = 1073741824,
SrvHighBeam = 2147483648
}

public void main()
{
int flagsInt;
Int32.TryParse(VA.GetText("statusFlags"), out flagsInt);
status flags = (status)flagsInt;

VA.SetText("statusFlags", flags.ToString());
}
}
« Last Edit: May 18, 2020, 08:22:16 AM by Pfeil »

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #9 on: April 21, 2020, 01:04:11 PM »
Is the 16842765 the total of all the flags or the number that I gave in the example. If I want to get the info for all the flags from this number it seems the number would be bigger?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #10 on: April 21, 2020, 01:07:40 PM »
You need to replace
Code: [Select]
Set text [statusFlags] to '16842765'with whatever you're using to get the flags value from "the status log of the player journal".

The number is just there as an example of a valid combination of flags; It is not, and has never been, the total value of all flags.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #11 on: April 21, 2020, 01:29:17 PM »
Ok maybe my explanation is confusing you because you know what your talking about and I don't or I just don't know what I am talking about, either way here is what I see when I look at the file at flags

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #12 on: April 21, 2020, 01:33:36 PM »
You need to put the number after the '"Flags":' marker into the "statusFlags" text variable, and after the inline function runs, "statusFlags" will contain the names (as listed in the inline function) of the active flags.


You asked how to get from a number to a set of flags, so I assume you already have a way of getting said number into VoiceAttack.


If not: How is this .json file written? Is it always a single line, or do newer entries get appended?

If it's a single entry, this should work:
Code: [Select]
Set text [statusFlags] to [C:\Status.json]
Inline C# Function: Elite:Dangerous flags to text, wait until execution finishes
Write [Blue] '{TXT:statusFlags}' to log
Begin Text Compare : [statusFlags] Contains 'InMainShip'
    Write [Blue] 'Currently in main ship' to log
Else
    Write [Blue] 'Currently not in main ship' to log
End Condition
(Obviously you'll need to substitute the actual path to your Status.json file)


Where "Elite:Dangerous flags to text" contains:
Code: [Select]
using System;

public class VAInline
{
[Flags]
enum status : uint
{
Docked = 1,
Landed = 2,
LandingGearDown = 4,
ShieldsUp = 8,
SuperCruise = 16,
FlightAssistOff = 32,
HardpointsDeployed = 64,
InWing = 128,
LightsOn = 256,
CargoScoopDeployed = 512,
SilentRunning = 1024,
ScoopingFuel = 2048,
SrvHandbrake = 4096,
SrvUsingTurretView = 8192,
SrvTurretRetracted = 16384,
SrvDriveAssist = 32768,
FsdMassLocked = 65536,
FsdCharging = 131072,
FsdCooldown = 262144,
LowFuel = 524288,
OverHeating = 1048576,
HasLatLong = 2097152,
IsInDanger = 4194304,
BeingInterdicted = 8388608,
InMainShip = 16777216,
InFighter = 33554432,
InSrv = 67108864,
HudInAnalysisMode = 134217728,
NightVision = 268435456,
AltitudeFromAverageRadius = 536870912,
FsdJump = 1073741824,
SrvHighBeam = 2147483648
}

public void main()
{
string statusInfo = VA.GetText("statusFlags") ?? "";

int flagsSectionStart = statusInfo.IndexOf("\"Flags\":") + 8;
if (flagsSectionStart == -1)
{
VA.WriteToLog("Error getting status flags: '\"Flags:\"' section not found", "red");
VA.SetText("statusFlags", "");
return;
}
int flagsSectionEnd = statusInfo.IndexOf(',', flagsSectionStart);

string flagsNumber = statusInfo.Substring(flagsSectionStart, flagsSectionEnd - flagsSectionStart);

int flagsInt;
Int32.TryParse(flagsNumber, out flagsInt);
status flags = (status)flagsInt;

VA.SetText("statusFlags", flags.ToString());
}
}
« Last Edit: May 18, 2020, 08:21:58 AM by Pfeil »

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #13 on: April 21, 2020, 08:01:14 PM »
The number changes, according to what is being used. ie: hud mode changes, supercruse, ship lights etc
BTW I finely found the inLine function and am trying to figure out where the info is stored that the function needs to use and what file to dump it to.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #14 on: April 21, 2020, 08:03:12 PM »
...I know that the number changes, that's the entire point. Have you actually tried the last example?

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #15 on: April 21, 2020, 08:05:21 PM »
yes I did the inline function but got errors, and the only this the text would type to the log was not in ship

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #16 on: April 21, 2020, 08:06:35 PM »
Which errors, exactly, and where?

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #17 on: April 21, 2020, 08:08:33 PM »
7:07:43.721 Currently not in main ship
7:07:43.668 Not set
7:07:43.520 Inline function compile contained 1 errors and cannot run
7:07:43.367 Recognized : 'test jason' (Confidence 92)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #18 on: April 21, 2020, 08:10:09 PM »
Compiles just fine on my machine. Double check that you copy-pasted it correctly.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #19 on: April 21, 2020, 08:12:39 PM »
here is the vap I have maybe i am missing something

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #20 on: April 21, 2020, 08:21:10 PM »
You have pasted the description of the inline function into the inline function action...
Where "Elite:Dangerous flags to text" contains:
means that you need to put what's in the "code" box under that line into the inline function; Replace everything in the main field (not the "Referenced Assemblies" field, the one below that with the lines numbers in it).


Also correct the initial setting of the "statusFlag" variable, where you added brackets to the variable name.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #21 on: April 21, 2020, 08:58:54 PM »
I have made a little progress but the inline function still has errors. Clearly I am not understanding what needs or does not need to be in there

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #22 on: April 21, 2020, 09:00:01 PM »
here is what I am seeing in the log

7:59:21.399 Currently not in main ship
7:59:21.394  "timestamp":"2020-04-22T02:59:11Z", "event":"Status", "Flags":16777224, "Pips":[4,4,4], "FireGroup":1, "GuiFocus":0, "Fuel": "FuelMain":28.790001, "FuelReservoir":0.834532 , "Cargo":184.000000, "LegalState":"Clean"

7:59:21.392 Inline function compile contained 2 errors and cannot run
7:59:21.285 Recognized : 'test jason' (Confidence 93)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #23 on: April 21, 2020, 09:02:56 PM »
You have pasted the description of the inline function into the inline function action...
Where "Elite:Dangerous flags to text" contains:
means that you need to put what's in the "code" box under that line into the inline function

Again you have put the action list description of the inline function into the inline function; That description, on my screen, is not in the "code" box underneath the line "Where "Elite:Dangerous flags to text" contains:".

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #24 on: April 21, 2020, 10:06:04 PM »
Ok I have tried a bunch of variations that of what I think your asking and I am not getting where

I included the code beneath the line "Elite:Dangerous Flags to text" the compiler does not like that. The code in the second box will compile but when I runs it I get errors.

I think you need to talk to me like I am a moron.

Or just give up I have taken a lot of your time up, maybe it time to give up on me understanding.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #25 on: April 22, 2020, 10:09:41 AM »
Go to the "Execute an Inline Function" action in your command and edit it.

Remove everything in the numbered list, make sure it's completely empty (you'll still see the first line marker, "1", on the left hand side)

On my post containing the last example, find the lower of the two "Code:" boxes, and next to the "Code:"label, click "Select", which should select everything in that box (and nothing else)

Press Ctrl-C on your keyboard (hold down the "Ctrl" key, press "C", then release the "Ctrl" key) to copy the text

Go back to the inline function you're editing, make sure you're in the main input field (which should now only have "1" in it), then press Ctrl-V (hold down the "Ctrl" key, press "V", then release the "Ctrl" key) to paste the text

Click "Compile" at the bottom-left corner of the window, you should see "Compile successful" in the list below the main field

Click "OK" at the bottom-right corner of the window

Click "OK" at the bottom-right corner of the "Edit a Command" window

Click "Apply" or "Done" at the bottom of the "Edit a Profile" window


You should now be able to execute the command; If there is a valid .json file at the path you specified, with the correct markup, matching the one you posted, you should get a list of flags in the log.

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #26 on: April 22, 2020, 11:25:49 AM »
Thank you
First the select is not working at least for me.
I followed you instructions, and when I either do a test run after compiling it, or when I test the command profile I get an error
10:19:24.494 not in main ship
10:19:24.488 TXT:statusFlags
10:19:24.457 Inline function execution exception: Exception has been thrown by the target of an invocation. Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex
10:19:24.424 Recognized : 'test jason' (Confidence 95)
I was having is problem last night that is why I thought I was doing it wrong, again I think I am missing something you are trying to tell me would be my guess.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #27 on: April 22, 2020, 11:33:39 AM »
That means the path to .json file isn't valid, which is because you have named it "statusFlag" instead of statusFlags"...


I put in error handling, but because the index gets added to that doesn't work (the root cause of the error is the invalid .json, still).

Replace the contents of the inline function with
Code: [Select]
using System;

public class VAInline
{
[Flags]
enum status : uint
{
Docked = 1,
Landed = 2,
LandingGearDown = 4,
ShieldsUp = 8,
SuperCruise = 16,
FlightAssistOff = 32,
HardpointsDeployed = 64,
InWing = 128,
LightsOn = 256,
CargoScoopDeployed = 512,
SilentRunning = 1024,
ScoopingFuel = 2048,
SrvHandbrake = 4096,
SrvUsingTurretView = 8192,
SrvTurretRetracted = 16384,
SrvDriveAssist = 32768,
FsdMassLocked = 65536,
FsdCharging = 131072,
FsdCooldown = 262144,
LowFuel = 524288,
OverHeating = 1048576,
HasLatLong = 2097152,
IsInDanger = 4194304,
BeingInterdicted = 8388608,
InMainShip = 16777216,
InFighter = 33554432,
InSrv = 67108864,
HudInAnalysisMode = 134217728,
NightVision = 268435456,
AltitudeFromAverageRadius = 536870912,
FsdJump = 1073741824,
SrvHighBeam = 2147483648
}

public void main()
{
string statusInfo = VA.GetText("statusFlags") ?? "";

int flagsSectionStart = statusInfo.IndexOf("\"Flags\":") + 8;
if (flagsSectionStart == 7)
{
VA.WriteToLog("Error getting status flags: '\"Flags:\"' section not found", "red");
VA.SetText("statusFlags", "");
return;
}
int flagsSectionEnd = statusInfo.IndexOf(',', flagsSectionStart);

string flagsNumber = statusInfo.Substring(flagsSectionStart, flagsSectionEnd - flagsSectionStart);

int flagsInt;
Int32.TryParse(flagsNumber, out flagsInt);
status flags = (status)flagsInt;

VA.SetText("statusFlags", flags.ToString());
}
}
« Last Edit: May 18, 2020, 08:21:42 AM by Pfeil »

Incurable-Rash

  • Full Member
  • ***
  • Posts: 181
Re: Elite dangerous flags values total
« Reply #28 on: April 22, 2020, 11:58:54 AM »
First thank you that worked.
I tried to write the same values the same way each time but clearly I missed up on a least one.

I would like to try and learn more about using inline functions, any suggestion of how to do that from scratch or should I learn other basics first.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Elite dangerous flags values total
« Reply #29 on: April 22, 2020, 12:08:07 PM »
At the very least you'll need to understand basic programming concepts.

For inline functions specifically, I'd recommend learning about C# as a language, and the .NET framework.