How do i check if a graphic file with a given name exists inside a mod or directory in lua for factorio? and if it doesn't, use a different graphics file instead?
something like if "__modname__/graphics/technology/techname.png" exists then tech.icon="__modname__/graphics/technology/techname.png" else tech.icon="__modname__/graphics/technology/nographic.png" end
or:
tech.icon="__modname__/graphics/technology/techname.png" or "__modname__/graphics/technology/nographic.png"
neither seem to work
check if graphic for icon usage exists or use "placeholder" graphic
-
- Long Handed Inserter
- Posts: 66
- Joined: Sun Aug 06, 2017 9:42 am
- Contact:
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: check if graphic for icon usage exists or use "placeholder" graphic
The data stage runs before texture loading, and thus even the engine itself probably doesn't know which files exist yet. In any case there is no way to check if a given file exists.
But you can test if a mod is installed:
Or you can just grab the icon from the other mods prototype:
But you can test if a mod is installed:
Code: Select all
if mods['mod-name'] == '1.0.0' then
end
Code: Select all
if data.raw.technology['other-mod-tech-name'] then
tech.icon = data.raw.technology['other-mod-tech-name'].icon
end
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.