Page 1 of 1

Can a script know the filename of its save?

Posted: Sat Jun 02, 2018 6:51 am
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

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

Posted: Sat Jun 02, 2018 8:06 am
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.

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

Posted: Sat Jun 02, 2018 8:22 am
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.

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

Posted: Sat Jun 02, 2018 8:39 am
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.

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

Posted: Mon Jun 04, 2018 5:13 am
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.

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

Posted: Mon Jun 04, 2018 5:29 am
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.

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

Posted: Mon Jun 04, 2018 12:56 pm
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.

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

Posted: Mon Jun 04, 2018 3:07 pm
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.