Page 1 of 1

[Rseding91][2.0.11] create_entity and not fast replacing ghosts

Posted: Fri Oct 25, 2024 11:46 pm
by PennyJim
I'm currently trying to modify the behavior of chests to make them rotatable. I got them working pretty damn well before I remembered that ghosts are now interactive.

To fix this, I did some code to get the ghost-name, and it mostly worked without any hitch. The problem is, the fact that I was relying on the circuit connections being preserved because I'm fast replacing the underlying assembling machines with chests, no longer works.

It took me some time to realize, but the 3 chests I was testing with (see bp string) were turning into 6 ghosts.. Meaning they, as part of the same fast replace group, were not getting fast replaced, but instead being built on top of each other (and not even destroying the old ghost like preserve_ghosts_and_corpses would imply)

I tried fast-replacing a normal chest ghost, and I saw that the bar was getting preserved, so it seems to be like fast replacing ghosts should be totally supported.

Edit: here's the commit of me discovering this bug. Just so you can maybe go back in the history and see the bp'ing working before I tried to modify ghosts.

Code: Select all

0eNqlVNtugzAM/ZXKz6FqKFQq0r5jD1OFApg2UkhoSHZRxb/PgbJ2K520jrwQJz7HPsdwgkJ5bK3UDrITyNLoDrKXE3Ryr4UKMS0ahAzeZIWRtEZH5QE7Bz0DqSt8h4z37N79wtc12puMuN8xQO2kkzjSDZuPXPumQEuQbIKxxgknCoWRxaMnmC84Bq3pCMHowEqoKwYflLpepsTkxL4L8VBGPibQrpS29PL6NW8MXTB1blq0YkQj9umU9KgGjhx1qKKCzFmPRHAuJ0B1WIYrYyeTKAxqqajan9FzX0roii4oauPohaLmKaiNbUQIlaZpBZVjSAt4GgI+OMRXqyDd3hrf0snzQbiFO+BiDDBovHKyVTJomAZbJsFnq9lcVMZaaqwiare06PCBqmjRw26sjGesvBqjGxf5Mh19TEjkStpRW8iSO57Okq5nSL/N4r3hSf49PPGvw1ML1T08PZeuwmdKczgkRtYUxv3NsXQYI0H5rzgVNfhH0TfSPNC+cMbZmvEdo7c4rB2dSocNYV3+Ggxeqcyh9XQTb5PtNk14Esec9/0nJct8bg==

Re: [2.0.12] create_entity and not fast replacing ghosts

Posted: Mon Oct 28, 2024 8:07 pm
by PennyJim
Okay I came back to this to try implementing a quick command to prove that the fast_replace is not working

Code: Select all

/c
entity = game.player.selected;
is_ghost = entity.name == "entity-ghost";
name = "steel-chest";
new_ent = entity.surface.create_entity{
	name = is_ghost and "entity-ghost" or name,
	inner_name = is_ghost and name or nil,
	position = entity.position,
	force = entity.force,
	fast_replace = true,
	spill = false,
};
game.print(entity and entity.valid, {skip=0});
game.print(new_ent and new_ent.valid, {skip=0});
Take this command, and if you run it while selecting an iron chest, you'll see it fast replaced into as steel chest. The original chest is now gone, as you can prove with a decon planner.
If you now run it while selecting the ghost of an iron chest, you'll now see both ghosts existing.

Now if you change the name variable to this line:

Code: Select all

name = is_ghost and entity.ghost_name or entity.name;
You'll see it duplicating the entity each and every time. I suspect it might be related to that, and a title of "create_entity doesn't fast replace when names match" might be more accurate.

Re: [2.0.11] create_entity and not fast replacing ghosts

Posted: Mon Oct 28, 2024 8:24 pm
by Rseding91
Thanks for the command to test with. So, fast-replacing ghosts with create_entity was never a thing that worked. Ghosts do not have a fast replace group defined and so the check do fast replace would always fail. However, I don't see a reason to not allow it so for the next release I've changed it to allow the fast-replace if the inner entity would allow it.

Re: [2.0.11] create_entity and not fast replacing ghosts

Posted: Mon Oct 28, 2024 8:30 pm
by PennyJim
I guess that reason for why it wouldn't originally makes sense to me,

But also, with how less and less special the ghosts have gotten (like how you can now interact with them near normally), the more I want them to act like a practically drop-in replacement for entities. Of course with the limitations of not being able to hold or affect anything.

I want my jank to work not so jankily :D
So thank you for facilitating this