Page 1 of 1

Any way to check whether a file exists?

Posted: Wed Jan 17, 2018 5:19 am
by knightofrust
I was recently tinkering with icons and a question arose: can I somehow check if a file exists before reading it, without using any third-party LUA libraries such as os./io. and the like?
Also, related question. In the mods's scripts paths to files are given like this

Code: Select all

__MODNAME__/FOLDER/FILE
What 'MODNAME' stands for? Is that an alias? What hides behind it?
Can there be a situation when not all of the active mods are in the same folder? Will 'MODNAME' referring to that out-of-folder mod's name give correct path then?

Re: Any way to check whether a file exists?

Posted: Wed Jan 17, 2018 9:08 am
by bobingabout
knightofrust wrote:I was recently tinkering with icons and a question arose: can I somehow check if a file exists before reading it, without using any third-party LUA libraries such as os./io. and the like?
Also, related question. In the mods's scripts paths to files are given like this

Code: Select all

__MODNAME__/FOLDER/FILE
What 'MODNAME' stands for? Is that an alias? What hides behind it?
Can there be a situation when not all of the active mods are in the same folder? Will 'MODNAME' referring to that out-of-folder mod's name give correct path then?
MODNAME is simply the name of the mod, as defined in info.json, and is also the name of the folder/zip file minus version numbers in the mods folder.

For example, Bob's ores mod is bobores, so would be addressed via __bobores__

Re: Any way to check whether a file exists?

Posted: Wed Jan 17, 2018 10:45 am
by knightofrust
bobingabout wrote:
knightofrust wrote:I was recently tinkering with icons and a question arose: can I somehow check if a file exists before reading it, without using any third-party LUA libraries such as os./io. and the like?
Also, related question. In the mods's scripts paths to files are given like this

Code: Select all

__MODNAME__/FOLDER/FILE
What 'MODNAME' stands for? Is that an alias? What hides behind it?
Can there be a situation when not all of the active mods are in the same folder? Will 'MODNAME' referring to that out-of-folder mod's name give correct path then?
MODNAME is simply the name of the mod, as defined in info.json, and is also the name of the folder/zip file minus version numbers in the mods folder.

For example, Bob's ores mod is bobores, so would be addressed via __bobores__
So there's no path to the mod's directory under __bobores__?

Re: Any way to check whether a file exists?

Posted: Wed Jan 17, 2018 4:20 pm
by eradicator
__yourmodname__ is the folder that info.json, data.lua, etc reside in. Ofc you can have subfolders after that. But the variable points to that folder. The game internally resolves that to the actual file system path because you have no knowledge of the actual path. Which also answers your OP question: No, you can not know if a file exists. It doesn't even need to exist in data stage. Only when all data has been loaded does the game check if the files actually exist.

During control(.lua) stage there are some functions to check if sprites exist though.