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
Cheking if a file/sprite exists.
Re: Cheking if a file/sprite exists.
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
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.
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.
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.
Re: Cheking if a file/sprite exists.
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.)
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.
You can use this function:Therenas wrote: ↑Sat Feb 02, 2019 9:23 pmHi, 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.)
https://lua-api.factorio.com/latest/Lua ... prite_path
Re: Cheking if a file/sprite exists.
Oh wow, would not have thought to check the GUI class, even though it seems kinda obvious. Thanks a lot!Klonan wrote: ↑Sat Feb 02, 2019 9:52 pmYou can use this function:
https://lua-api.factorio.com/latest/Lua ... prite_path