API usage validation

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Thu May 18, 2017 2:22 pm
Contact:

API usage validation

Post by danielbrauer »

I recently encountered a problem where other mods are not correctly passing an entity when raising the script_raised_built event. I can program defensively, but the current situation means every mod developer needs to program defensively just to avoid errors.

It would be super cool if Factorio considered it an error to pass a table to an event which does not have exactly the fields defined in the API.

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 445
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: API usage validation

Post by Therax »

Can we say at least the fields defined in the API? It may still be useful to raise this event manually with additional context.
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Boodals
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: API usage validation

Post by Boodals »

I think you just chalk this up to a broken mod.
I agree that you shouldn't have to check defensively, especially with events that are typically from the game, but if you wanted to enforce it then there's a lot of edge cases it would need to look out for. eg. can you not send optional data? what about events where you get multiple optional data together in a group? if that logic wasn't also enforced you could still break it. In the end, it would be super convoluted and hard to maintain, and it's something so rare that it just wouldn't be worth it.

With script_raised_built I recommend checking for entity or created_entity. Before 0.17 there wasn't an official standard in the api doc, so people used either. I personally use created_entity because that's what all the other on_built events use, but I guess I should change over to entity if that's what the api says.

Post Reply

Return to “Modding interface requests”

Who is online

Users browsing this forum: Bing [Bot]