Page 1 of 1
Invisible/visible but still selectable entity ?
Posted: Sat Apr 23, 2016 11:21 pm
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 ?
Re: Invisible/visible but still selectable entity ?
Posted: Tue Apr 26, 2016 2:20 pm
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
Re: Invisible/visible but still selectable entity ?
Posted: Tue Apr 26, 2016 3:22 pm
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...
