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

Place to get help with not working mods / modding interface.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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?
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post by DaveMcW »

Pick a different symbol to join them with, like "|"
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post by mrvn »

Until the next mod decides to use that too. :(
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

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

Post 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.
Post Reply

Return to “Modding help”