Author Topic: Mission Timer as .txt  (Read 1789 times)

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Mission Timer as .txt
« on: January 19, 2019, 05:39:29 AM »
I could probably dive though tones of postings but I'll ask here too in case someone has it to hand

On Distant Worlds 2 and I would like a have a mission timer to display on my stream.

What I would like is to put in the start date and time and for the script to calculate in Months, weeks, days, hours, mins & seconds and have that saved as a .txt file every second so I have a continuous mission timer type thing.
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Mission Timer as .txt
« Reply #1 on: January 24, 2019, 09:20:42 AM »
ok I've looked though the forums for past posts and I have found this posting here. It's kinda what I'm looking for.

Made some adjustments and I got partly what I want. I got the days to work but I don't know how to get the hours, minutes and seconds.

https://forum.voiceattack.com/smf/index.php?topic=655.0


Code: [Select]
Set date [TargetDate] value to 13/01/2019 16:09:20
Set integer [DaysToTarget] value to the converted value of {EXP: ({DATETICKS} - {DATETICKS:TargetDate}) / 864000000000}
Write [Blue] 'Start Date & Time ({DATE:TargetDate}):- Mission time: {INT:DaysToTarget} Days : {INT:HoursToTarget} Hours :  {INT:MinutesToTarget} Minutes :  {INT:SecondsToTarget} Secords' to log

Results:
Quote
Start Date & Time (January 13, 2019):- Mission time: 11 Days : Not set Hours :  Not set Minutes :  Not set Seconds
« Last Edit: January 24, 2019, 10:12:45 AM by Bumble B »
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Mission Timer as .txt
« Reply #2 on: January 24, 2019, 11:45:07 AM »
Instead of reinventing the wheel and doing the math manually, I'd use an inline function:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
DateTime startTime = VA.GetDate("startTime") ?? DateTime.MinValue;
TimeSpan elapsedTime = DateTime.Now - startTime;
VA.SetText("elapsedTime", "Start Date & Time (" + startTime + "):- Mission time: " + elapsedTime.Days + " Days : " + elapsedTime.Hours + " Hours :  " + elapsedTime.Minutes + " Minutes :  " + elapsedTime.Seconds + " Seconds");
}
}

You could have it set int values instead of the ready-made string, if you prefer.

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Mission Timer as .txt
« Reply #3 on: January 24, 2019, 12:08:21 PM »
Instead of reinventing the wheel and doing the math manually, I'd use an inline function:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
DateTime startTime = VA.GetDate("startTime") ?? DateTime.MinValue;
TimeSpan elapsedTime = DateTime.Now - startTime;
VA.SetText("elapsedTime", "Start Date & Time (" + startTime + "):- Mission time: " + elapsedTime.Days + " Days : " + elapsedTime.Hours + " Hours :  " + elapsedTime.Minutes + " Minutes :  " + elapsedTime.Seconds + " Seconds");
}
}

You could have it set int values instead of the ready-made string, if you prefer.

Not sure what you mean by the ready-made string. I can't readily see where I would put a start date cause right now its calculates from 01/01/0001 00:00:00

Separate command to set the start date
Code: [Select]
Set date [startTime] value to 13/01/2019 20:20:20 (save value to profile)

Found that part :D

and how would I make it update every second or min? It seems to take a few seconds for it to update when i do execute the script

Code: [Select]
using System;

public class VAInline
{
public void main()
{
DateTime startTime = VA.GetDate("startTime") ?? DateTime.MinValue;
TimeSpan elapsedTime = DateTime.Now - startTime;
VA.SetText("elapsedTime", " Distant Worlds 2 Mission time: " + elapsedTime.Days + " Days : " + elapsedTime.Hours + " Hours :  " + elapsedTime.Minutes + " Minutes :  " + elapsedTime.Seconds + " Seconds");
}
}
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Mission Timer as .txt
« Reply #4 on: January 24, 2019, 01:14:36 PM »
Update what exactly? Running the inline function and writing to a text file should only take a few milliseconds.

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Mission Timer as .txt
« Reply #5 on: January 24, 2019, 03:55:43 PM »
ok my bad, i was updating the .txt file though my network on another computer. Sorted it now and updates every second when I put it in a start loop while stateTime is has been set
Code: [Select]
Start Loop While : [startTime] Has Been Set
Inline C# Function:
Pause 1 second
DISABLED - Write [Blue] '{TXT:elapsedTime}' to log
Write (overwrite), '{TXT:elapsedTime}' to file '%USERPROFILE%\Documents\EDDI2\Exploration\Expedition Time.txt'
End Loop
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Mission Timer as .txt
« Reply #6 on: February 05, 2019, 02:01:45 PM »
possible to get this so show weeks too? I tried just adding + elapsedTime.Weeks + " Weeks : " into the inline code but get errors
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Mission Timer as .txt
« Reply #7 on: February 05, 2019, 07:39:27 PM »
Quote from: https://docs.microsoft.com/en-us/dotnet/api/system.timespan#remarks
The largest unit of time that the TimeSpan structure uses to measure duration is a day. Time intervals are measured in days for consistency, because the number of days in larger units of time, such as months and years, varies.


If you need weeks, you'll have to do the math. Assuming you're dealing with blocks of 7 days, that could look like this:
Code: [Select]
using System;

public class VAInline
{
public void main()
{
DateTime startTime = VA.GetDate("startTime") ?? DateTime.MinValue;
TimeSpan elapsedTime = DateTime.Now - startTime;

int remainingDays = 0;
int weeks = Math.DivRem(elapsedTime.Days, 7, out remainingDays);

VA.SetText("elapsedTime", "Start Date & Time (" + startTime + "):- Mission time: " + weeks + " Weeks : " + remainingDays + " Days : " + elapsedTime.Hours + " Hours :  " + elapsedTime.Minutes + " Minutes :  " + elapsedTime.Seconds + " Seconds");
}
}

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Mission Timer as .txt
« Reply #8 on: February 06, 2019, 11:01:48 AM »
beautiful just beautiful :)

many thanks
--
CMDR Bumble B ö7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer