Cheking if a file/sprite exists.

Place to get help with not working mods / modding interface.
longtomjr
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Mar 25, 2017 8:44 am
Contact:

Cheking if a file/sprite exists.

Post by longtomjr »

I am working on creating a mod that overlay some graphics in the game.

The functionality I want is to be able to check whether or not a certain file exists. It seems like "io" is not implemented in Factorio.
If anyone has any ideas on how to do this without creating a data object for each icon you change, feel free to share.

Longtomjr

Helfima
Fast Inserter
Fast Inserter
Posts: 200
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Cheking if a file/sprite exists.

Post by Helfima »

you can use pcall to escape error

see https://github.com/Helfima/helmod/blob/ ... i.lua#L217

if sprite doesn't exist i put a text button

Rseding91
Factorio Staff
Factorio Staff
Posts: 14142
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Cheking if a file/sprite exists.

Post by Rseding91 »

There is no way to do that. Additionally it doesn't matter because there's no way to hot-load sprites runtime so it doesn't matter.

What's your use-case anyway? There's most likely a better way to do what you're trying.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 249
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Cheking if a file/sprite exists.

Post by Therenas »

Hi, sorry to dig this up, but I have a problem that this would also solve.
I'm working on a GUI-mod, and it displays item-sprites that the user can choose. Now if you add a modded one, and then remove that mod, I can no longer display it obviously. I would like to display a default image instead. Now Helfima's suggestion of catching the error is a solution, but it would be nice if we could check if sprites exist. (The sprites you use on a sprite-button.)

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5246
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Cheking if a file/sprite exists.

Post by Klonan »

Therenas wrote:
Sat Feb 02, 2019 9:23 pm
Hi, sorry to dig this up, but I have a problem that this would also solve.
I'm working on a GUI-mod, and it displays item-sprites that the user can choose. Now if you add a modded one, and then remove that mod, I can no longer display it obviously. I would like to display a default image instead. Now Helfima's suggestion of catching the error is a solution, but it would be nice if we could check if sprites exist. (The sprites you use on a sprite-button.)
You can use this function:
https://lua-api.factorio.com/latest/Lua ... prite_path

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 249
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Cheking if a file/sprite exists.

Post by Therenas »

Klonan wrote:
Sat Feb 02, 2019 9:52 pm
You can use this function:
https://lua-api.factorio.com/latest/Lua ... prite_path
Oh wow, would not have thought to check the GUI class, even though it seems kinda obvious. Thanks a lot!

Post Reply

Return to “Modding help”