Page 1 of 1

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

Posted: Mon Nov 05, 2018 1:49 am
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

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

Posted: Mon Nov 05, 2018 8:57 am
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