Custom Data

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2144
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Custom Data

Post by Ranakastrasz »

I am trying to add custom data to a particular prototype, so as to carry extra data. It also needs to support multiple mods, for it to work properly.

Approach one is to use a Remote Interface to build a table. However, while it works, I have no idea how to handle mod updates or mod removal. In those cases, the table will no longer be accurate, and unlike data, doesn't get rebuilt. I am unsure how to properly detect and rebuild it correctly, which means it will end up stacking multiple copies of stuff or have entries that should be removed left behind.

Approach two is to use a prototype to carry the information. Since data is global between mods, and easily overwritten, it should work better. However, since you can't just add extra data to prototypes, I would need a dummy prototype which carries this information. It should be possible to, on game load, find all such dummy prototypes and load them into a table to be used. However, I would need a prototype that I can access the proper information for it to work.

Any mod that already handles this kind of problem would be helpful. I looked at treefarm, but I can't figure out how it de-registers or handles updates.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3705
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Custom Data

Post by DaveMcW »

The best prototype for custom data is the constant combinator. You get 15 integers and 15 item signals.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2144
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Custom Data

Post by Ranakastrasz »

Not what I meant, I don't think. I don't need to store data in an entity ingame, I need to attach extra data to prototypes.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Custom Data

Post by DedlySpyder »

So, the first idea is to have a base mod that handles the table storage with remote calls that your others ones access to add/remove/etc?

You could handle partial mod removal by having that base mod check active_mods when on_configuration_changed is fired, to remove anything relevant (one of the elements in the table being the mod that added it).

I guess you would also need a meta table to store which mods are actually in use so it would know what it has to check for

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Custom Data

Post by aubergine18 »

Lua supports weak tables, that will automatically drop entries that are no longer referenced from elsewhere. More info here: http://lua-users.org/wiki/WeakTablesTutorial
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Custom Data

Post by Adil »

There's the mod on portal, which allows accessing data.raw from ingame. (Named accordingly. Something like: data.raw...)
I believe any custom field should be carried over by this mod as well.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
mojo2012
Inserter
Inserter
Posts: 25
Joined: Fri Apr 01, 2016 8:05 am
Contact:

Re: Custom Data

Post by mojo2012 »

You can use the factorio-stdlib API, it does the actual storage in the global context though.

Post Reply

Return to “Modding help”