blueprint icons table - editing vs replacing

Place to get help with not working mods / modding interface.
User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 184
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

blueprint icons table - editing vs replacing

Post by moon69 »

Hi everyone,

I want some help please to understand lua & the Factorio API a bit better...

I wanted my mod to change one of the icons for the blueprint held in the hand.

The current blueprint icon is an item = "iron-plate" and I want to change it to "pipe", so I thought I could just do this:

Code: Select all

player.cursor_stack.blueprint_icons[1].signal.name = "pipe"
No errors from this, but no icon change either.

I initially thought it might be related to this bug report: [0.15.3] Cannot set blueprint_icons

After much trial and error (and cussing) I got it working like this:

Code: Select all

local blueprintIcons = player.cursor_stack.blueprint_icons
blueprintIcons[1].signal.name = "pipe"
player.cursor_stack.blueprint_icons = blueprintIcons
Why does the 2nd work where the first doesn't? I thought that a "local" table variable was just a pointer to the same anonymous table?

Looking at LuaItemStack.blueprint_icons in the Factorio API, it shows:
blueprint_icons :: array of Icon [Read-Write]
Icons of a blueprint item. Every entry of this array has the following fields:

signal :: SignalID: Slot icon to use. The slot will have the icon of the specified signal. This allows the use of any item icon, as well as virtual signal icons.
index :: uint: Index of the icon in the blueprint icons slots. Has to be in {1, 2, 3, 4}.
Can only be used if this is BlueprintItem
Does the "array of" signify anything? I understood lua arrays are just tables?

I've got it all working now, but would love to understand why!!
Rseding91
Factorio Staff
Factorio Staff
Posts: 16016
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: blueprint icons table - editing vs replacing

Post by Rseding91 »

"array of" means it's indexed using numbers. "table of" is a string key <> value mapping.
If you want to get ahold of me I'm almost always on Discord.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: blueprint icons table - editing vs replacing

Post by DaveMcW »

moon69 wrote:I've got it all working now, but would love to understand why!!
It costs too much effort/performance to write a fully accessible blueprint table. So you have to request a copy of the real table, edit it, then replace the real table with your copy.

If the limiting factor is only developer effort, you can ask nicely for a better way in Modding interface requests. But if it hurts performance, it is not likely to happen.
User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 184
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

Re: blueprint icons table - editing vs replacing

Post by moon69 »

Thanks both - no need for change... I just wanted to understand :)
Post Reply

Return to “Modding help”