Page 1 of 1

Cheking if a file/sprite exists.

Posted: Wed Mar 29, 2017 2:50 pm
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

Re: Cheking if a file/sprite exists.

Posted: Wed Mar 29, 2017 3:44 pm
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

Re: Cheking if a file/sprite exists.

Posted: Wed Mar 29, 2017 3:53 pm
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.

Re: Cheking if a file/sprite exists.

Posted: Sat Feb 02, 2019 9:23 pm
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.)

Re: Cheking if a file/sprite exists.

Posted: Sat Feb 02, 2019 9:52 pm
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

Re: Cheking if a file/sprite exists.

Posted: Sat Feb 02, 2019 10:46 pm
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!