Invalid filename (formerly: player.systemtime returns null) [SOLVED]

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
user1679
Posts: 761
Joined: Fri, 20. Jul 18, 23:20

Invalid filename (formerly: player.systemtime returns null) [SOLVED]

Post by user1679 » Tue, 30. Aug 22, 09:06

.


Go to solution


I'm trying to get a date/time string to use in my debug filename in an aiscript but it keeps causing "illegal filename" errors in the debug log.

First I tried:

<set_value name="$debugFile" exact="md.$SystemTimeAtGamestart + '_' + this.ship.name + ' (' + this.ship.idcode + ')' + '_log.txt'"

and it resulted in "Invalid property lookup: md.$SystemTimeAtGamestart"


Then I tried:

<set_value name="$debugFile" exact="player.systemtime.{'%Y-%m-%d_%H-%M-%S'} + '_' + this.ship.name + ' (' + this.ship.idcode + ')' + '_log.txt'"

and it resulted in "illegal filename: null_Elite Vanguard (NPC-168)_log.txt"

According to scriptproperties.xml, player.systemtime.{$string} uses standard C++ formatting options %Y = 4-digit year, %m = 2-digit month, etc.
Last edited by user1679 on Wed, 31. Aug 22, 05:00, edited 2 times in total.

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13289
Joined: Sun, 15. Feb 04, 20:12
x4

Re: player.systemtime returns null

Post by euclid » Tue, 30. Aug 22, 14:50

I suspect the ship's details causing trouble here because both, md.$SystemTimeAtGamestart and player.systemtime.{'%Y-%m-%d_%H-%M-%S'}, working fine for me. Btw. both are related (see md>setup.xml line 78) via

Code: Select all

  <set_value name="md.$SystemTimeAtGamestart" exact="player.systemtime.{'%Y-%m-%d_%H-%M-%S'}" />
Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

user1679
Posts: 761
Joined: Fri, 20. Jul 18, 23:20

Re: player.systemtime returns null

Post by user1679 » Wed, 31. Aug 22, 03:23

euclid wrote:
Tue, 30. Aug 22, 14:50
I suspect the ship's details causing trouble here because both, md.$SystemTimeAtGamestart and player.systemtime.{'%Y-%m-%d_%H-%M-%S'}, working fine for me. Btw. both are related (see md>setup.xml line 78) via

Code: Select all

  <set_value name="md.$SystemTimeAtGamestart" exact="player.systemtime.{'%Y-%m-%d_%H-%M-%S'}" />
Cheers Euclid
Thanks, that's where I got the idea when md.$SystemTimeAtGamestart didn't work.

You're right, the ship info was causing an illegal filename. Though I don't know why since there are
no illegal characters for a Windows filesystem in null_Elite Vanguard (NPC-168)_log.txt

This works:

<set_value name="$debugFile" exact="player.systemtime.{'%Y-%m-%d_%H-%M-%S'} + '_log.txt'" />


Not sure why md.$SystemTimeAtGamestart can't be invoked from an aiscript. The exact error is:
[=ERROR=] 149.31 Error in AI script test_aiscript on entity 0x144223: Property lookup failed: md
* Expression: md.$SystemTimeAtGamestart + '_log.txt'
* Action: <set_value>, line 66

user1679
Posts: 761
Joined: Fri, 20. Jul 18, 23:20

Re: player.systemtime returns null

Post by user1679 » Wed, 31. Aug 22, 04:58

.


SOLUTION


So it appears that even though () or [] are valid characters for a filename, the filewriter used by X4 doesn't allow it.

This works:

<set_value name="$debugFile" exact="player.systemtime.{'%Y%m%d-%H%M%S'} + '_' + this.ship.name + this.ship.idcode + '.log'"

and results in: 20220830-224509_Elite Sentinel ZDS-839.log


But this doesn't work:

<set_value name="$debugFile" exact="player.systemtime.{'%Y%m%d-%H%M%S'} + '_' + this.ship.name + ' (' + this.ship.idcode + ').log'"

and results in a debug log error:
[=ERROR=] 142.00 Error in AI script test_aiscript on entity 0x14a03b: Illegal file name '20220830-225443_Elite Sentinel (IZR-477).log'
* Expression: $debugFile
* Action: <debug_to_file>, line 220

Post Reply

Return to “X4: Foundations - Scripts and Modding”