Page 1 of 1

How to construct a virtual-signal from to entity names and how to split it?

Posted: Wed Oct 27, 2021 11:49 pm
by mrvn
I'm building virtual signals that are a combination of a locomotive and a wagon, for example "locomotive" and "artillery-wagon" for a vanilla example. With modes I have things like "locomotive-2" and "cargo-wagon-2".

I've starts by joining them with "-", so I get "train-locomotive-artillery-wagon". Then I split at "-" and take the 2nd and 3rd+4th parts to get the entities in vanilla. But with mods having "-" in the entity name that breaks for obvious reasons.

So how do I name my virtual signals so that I can later take them apart again to get the entity names?
Or how do I store a table of all signals with their source entity names in data.lua so control.lua can later access it?

Re: How to construct a virtual-signal from to entity names and how to split it?

Posted: Wed Oct 27, 2021 11:51 pm
by DaveMcW
Pick a different symbol to join them with, like "|"

Re: How to construct a virtual-signal from to entity names and how to split it?

Posted: Thu Oct 28, 2021 12:08 am
by mrvn
Until the next mod decides to use that too. :(

Re: How to construct a virtual-signal from to entity names and how to split it?

Posted: Thu Oct 28, 2021 12:16 am
by DaveMcW
You can add a sanity check to make sure your split entities actually exist.

If a mod is using "|", you probably don't want to be compatible with it anyway.

Re: How to construct a virtual-signal from to entity names and how to split it?

Posted: Thu Oct 28, 2021 12:24 am
by mrvn
DaveMcW wrote: Thu Oct 28, 2021 12:16 am You can add a sanity check to make sure your split entities actually exist.
That might actually be a working solution even when using "-". I don't expect any mod to add a locomotive "locomotive-cargo" and cargo wagon "wagon". That would create a duplicate signal name but I can fail that in data.lua.

Thanks.

This gave me a better idea though. In on_init/on_configuration_changed I can go over game.entity_prototypes and re-create all signal names again and save a table of signal name -> entity. I totally forgot I have access to the entity prototypes in control.lua too (at some points). That way I can do a simple lookup instead of trying to match entity names on every use. I kind of need that split often.