check if graphic for icon usage exists or use "placeholder" graphic

Place to get help with not working mods / modding interface.
usafphoenix
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sun Aug 06, 2017 9:42 am
Contact:

check if graphic for icon usage exists or use "placeholder" graphic

Post by usafphoenix »

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
User avatar
eradicator
Smart Inserter
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

Post by eradicator »

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:

Code: Select all

if mods['mod-name'] == '1.0.0' then
  end 
Or you can just grab the icon from the other mods prototype:

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.
Post Reply

Return to “Modding help”