Any way to check whether a file exists?

Place to get help with not working mods / modding interface.
Post Reply
knightofrust
Inserter
Inserter
Posts: 23
Joined: Fri Feb 13, 2015 10:45 am
Contact:

Any way to check whether a file exists?

Post 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?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Any way to check whether a file exists?

Post 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__
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

knightofrust
Inserter
Inserter
Posts: 23
Joined: Fri Feb 13, 2015 10:45 am
Contact:

Re: Any way to check whether a file exists?

Post 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__?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Any way to check whether a file exists?

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”