I'm having trouble changing textures, but numeric properties work fine

Place to get help with not working mods / modding interface.
Asky00
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Jan 30, 2021 3:29 pm
Contact:

I'm having trouble changing textures, but numeric properties work fine

Post by Asky00 »

Hi there. I have to say this is the first mod I'm writing.
The goal of the mod is to change the lamp textures and color mapping to improve readability of vanilla sev-seg displays.
While I had zero problems with color mapping and light intensities (which I only tuned), I can't find any solution to the texture problem.
The problems are:
  • the in-game icon doesn't change
  • the game fails to load because of (translated): Unable to load mod: "__lamp-retexture__/data-final-fixes.lua:27:attempt to index field '?' (a nil value)
    stack traceback:
    --lamp-retexture__/data-final-fixes.lua:27: in main chunk"
    Mods which will be disabled:
    - lamp-retexture (0.1.0)
Does anyone know a solution? I've checked for hours on this same forum, on the api documentation, on the prototypes, on other mods, but I'm surely missing something.
I'm running factorio 1.1.19 on Windows 10.
To avoid misunderstading: I identified the first non-blocking problem by deleting/commenting the entity texture override. Also, english is not my first language (sorry if I did mistakes or sounded rude, that wasn't my intention).

Code: Select all

--data-final-fixes.lua
--INIT
local lamp = data.raw.lamp["small-lamp"]
local mod = "__lamp-retexture__"
local iconpath = mod.."/graphics/icons/"
local entitypath = mod.."/graphics/entity/small-lamp/"
--ICON
log("icon before: "..lamp.icon)
lamp.icon = iconpath.."small-lamp.png"
log("icon after: "..lamp.icon)
--MAPPING
lamp.light = {intensity = 0.9, size = 1, color = {r=1.0, g=1.0, b=1.0}}
lamp.light_when_colored = {intensity = 1, size = 1, color = {r=1.0, g=1.0, b=1.0}}
lamp.glow_size = 1 --6
lamp.signal_to_color_mapping =
{
  {type="virtual", name="signal-black", color={r=0,g=0,b=0}}, -- added black
  {type="virtual", name="signal-grey", color={r=0.5,g=0.5,b=0.5}}, -- added grey
  {type="virtual", name="signal-red", color={r=1,g=0,b=0}},
  {type="virtual", name="signal-green", color={r=0,g=1,b=0}},
  {type="virtual", name="signal-blue", color={r=0,g=0,b=1}},
  {type="virtual", name="signal-yellow", color={r=1,g=1,b=0}},
  {type="virtual", name="signal-pink", color={r=1,g=0,b=1}},
  {type="virtual", name="signal-cyan", color={r=0,g=1,b=1}}
}
-- LAMP ENTITY TEXTURES
lamp.picture_off.layers[0].filename = entitypath.."lamp.png"
lamp.picture_off.layers[1].filename = entitypath.."lamp-shadow.png"
lamp.picture_off.layers[0].hr_version.filename = entitypath.."hr-lamp.png"
lamp.picture_off.layers[1].hr_version.filename = entitypath.."hr-lamp-shadow.png"
lamp.picture_on.layers[0].filename = entitypath.."lamp-light.png"
lamp.picture_on.layers[0].hr_version.filename = entitypath.."hr-lamp-light.png"
Attachments
factorio-current.log
(3.99 KiB) Downloaded 93 times
lamp-retexture_0.1.0.zip
(111.69 KiB) Downloaded 86 times
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 586
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: I'm having trouble changing textures, but numeric properties work fine

Post by Silari »

lamp.picture_on.layers[0].filename = entitypath.."lamp-light.png"
lamp.picture_on.layers[0].hr_version.filename = entitypath.."hr-lamp-light.png"
The picture_on property of lamps doesn't have a layers property that I can see in data.raw, as it uses a single set of definitions. Trying to index the layers property when there isn't one will cause the error it showed.

That would mean those two lines should be
lamp.picture_on.filename = entitypath.."lamp-light.png"
lamp.picture_on.hr_version.filename = entitypath.."hr-lamp-light.png"

You can grab a file with a dump of all of data.raw at https://wiki.factorio.com/Data.raw . It's quite useful for modding as it's basically all the vanilla prototypes' definitions.
Asky00
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Jan 30, 2021 3:29 pm
Contact:

Re: I'm having trouble changing textures, but numeric properties work fine

Post by Asky00 »

Thank you for your help!
Your suggestion fixed the picture_on problem.
I just found that the layer index on picture_off starts from 1, so that is also fixed.

The icon still doesn't work and even looking at the data.raw I can't figure it out.
Now the code looks like this.

Code: Select all

-- data-final-fixes.lua
-- INIT
local lamp = data.raw.lamp["small-lamp"]
local mod = "__lamp-retexture__"
local iconpath = mod.."/graphics/icons/"
local entitypath = mod.."/graphics/entity/small-lamp/"
-- ICON
lamp.icon = iconpath.."small-lamp.png" --THIS THING STILL HASN'T EFFECT IN-GAME
lamp.icon_mipmaps = 4 
lamp.icon_size = 64
-- LAMP ENTITY TEXTURES
lamp.picture_off.layers[1].filename = entitypath.."lamp.png"
lamp.picture_off.layers[2].filename = entitypath.."lamp-shadow.png"
lamp.picture_off.layers[1].hr_version.filename = entitypath.."hr-lamp.png"
lamp.picture_off.layers[2].hr_version.filename = entitypath.."hr-lamp-shadow.png"
lamp.picture_on.filename = entitypath.."lamp-light.png"
lamp.picture_on.hr_version.filename = entitypath.."hr-lamp-light.png"
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 586
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: I'm having trouble changing textures, but numeric properties work fine

Post by Silari »

I ALWAYS forget that LUA arrays are 1 indexed.

If you're looking at it's icon in the crafting menu, I believe that's taken from the item form of the lamp - data.raw.items["small-lamp"]. So you'd need
data.raw.items["small-lamp"].icon = iconpath.."small-lamp.png"
IN ADDITION TO the line you already have. The one you're editing is the icon for the entity itself, which IIRC is used in things like the Power Consumption menu. Not sure on that and can't verify in game right now.

As an aside, if you haven't been using it, the Prototype browser is extremely helpful - by default it's Ctrl+Shift+E. It lets you look at the properties of all the prototypes in the game as loaded, and includes a handy search.
Asky00
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Jan 30, 2021 3:29 pm
Contact:

Re: I'm having trouble changing textures, but numeric properties work fine

Post by Asky00 »

Perfect! Now everything works. Thank you!
I'll leave the mod as attachment.
Attachments
lamp-retexture_0.1.0.zip
(35.58 KiB) Downloaded 87 times
Post Reply

Return to “Modding help”