Invisible/visible but still selectable entity ?

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Invisible/visible but still selectable entity ?

Post by binbinhfr »

Hi,

I'd like to have an 1x1 entity (container type) that I could make visible or invisible, but always selectable/operable.
Is it possible ? How would you do this ?
My mods on the Factorio Mod Portal :geek:
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Invisible/visible but still selectable entity ?

Post by daniel34 »

No, it's not directly possible because that is stored in the entity prototype.
The workaround would be to have two identical entities, except one has a transparent image.
Whenever you wanted to switch visibility you'd need to remove one chest and place another, copying the contents.

Something like (as I already had this coded sometime ago)

Code: Select all

function replaceChest(sourceChest, targetChestName)
	local inv = sourceChest.get_inventory(defines.inventory.chest)
	local entity = sourceChest.surface.create_entity{
		name = targetChestName, 
		position = sourceChest.position, 
		force = sourceChest.force,
		bar = inv.getbar()}
	if inv.getbar() == #inv then
		entity.get_inventory(defines.inventory.chest).setbar()
	end
	for i = 1, #inv do
		entity.get_inventory(defines.inventory.chest)[i].set_stack(inv[i]);
	end
	sourceChest.destroy()
end
quick links: log file | graphical issues | wiki
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Invisible/visible but still selectable entity ?

Post by binbinhfr »

daniel34 wrote:No, it's not directly possible because that is stored in the entity prototype.
The workaround would be to have two identical entities, except one has a transparent image.
Whenever you wanted to switch visibility you'd need to remove one chest and place another, copying the contents.
OK, that's what I wanted to avoid, but if we have no choice... :-)
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Modding help”