Can a script know the filename of its save?

Things that we aren't going to implement
adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Can a script know the filename of its save?

Post by adamius »

Hi all,

I'd like a script to be able to know what save its world came from. I can't seem to find anything relevant.

Ideally I'd find it in game.savename or something similar.

Any ideas?

thanks
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Can a script know the filename of its save?

Post by Bilka »

This is not possible to access because it is not a deterministic value. Mods have to be deterministic, so they may not have access to non-deterministic values.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: Can a script know the filename of its save?

Post by adamius »

Bilka wrote:This is not possible to access because it is not a deterministic value. Mods have to be deterministic, so they may not have access to non-deterministic values.
Your reality apparently contains insufficient hamster actuator power. This function from LuaGameScript (game) also disagrees with your statement.

server_save(name)
Instruct the server to save the map.

Parameters
name :: string (optional): Save name. If not specified, writes into the currently-running save.

I'd actually like to know where this name comes from then... so I can give it to my lua script.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3725
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Can a script know the filename of its save?

Post by DaveMcW »

adamius wrote:I'd actually like to know where this name comes from then... so I can give it to my lua script.
The name comes from you. You can rename a save, but you cannot determine its original name.
adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: Can a script know the filename of its save?

Post by adamius »

DaveMcW wrote:
adamius wrote:I'd actually like to know where this name comes from then... so I can give it to my lua script.
The name comes from you. You can rename a save, but you cannot determine its original name.
That is why I posted this in the Modding interface requests forum. I have a mod that would make use of this information yet it is currently not available for a mod to use. And it was passed in from command line so it’s value as passed in is absolutely deterministic.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Can a script know the filename of its save?

Post by eradicator »

Anyone who joins a server loads the game from an auto-generated savegame made in the exact moment they try to join. So the "original" savegame name would have to be explicitly synced to the client afterwards to be deterministic.

Also requests are much more likely to be implemented if you properly explain what you need them for :P.
adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: Can a script know the filename of its save?

Post by adamius »

eradicator wrote:Anyone who joins a server loads the game from an auto-generated savegame made in the exact moment they try to join. So the "original" savegame name would have to be explicitly synced to the client afterwards to be deterministic.

Also requests are much more likely to be implemented if you properly explain what you need them for :P.
The “what” is in the title of the post. The “how” is up to the devs. I could suggest that this be implemented such that when a save is created its filename is embedded inside the file when the file is saved. Obviously you wouldn’t write the temp filename when syncing to multiplayer clients due to determinism. The “why” is simple enough, I’d like a mod to be able to draw the filename on the world surface for identification purposes and to do that I simply need the filename of the zip file as it was passed to the headless server command line. The server obviously knows this filename at load time and it will use it to save its local copy. And the server knew this filename when it last saved it. The client copy would also be able to read this value as it gets a copy of the dynamically generated file from the server. In single player mode no desync is possible.

For clarification, which part of “Can a script know the filename of its save?” is unclear?
Eg if the save file was called myworld.zip, then the script inside a mod could access game.savename to get it.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Can a script know the filename of its save?

Post by eradicator »

adamius wrote:The “why” is simple enough, I’d like a mod to be able to draw the filename on the world surface for identification purposes
Apparently i erroneously wrote "what" instead of "why". This was missing.
adamius wrote:For clarification, which part of “Can a script know the filename of its save?” is unclear?
The "what" part was just fine.
Post Reply

Return to “Won't implement”