Providing a useful message for startup errors

Place to get help with not working mods / modding interface.
Post Reply
Coppermine
Long Handed Inserter
Long Handed Inserter
Posts: 79
Joined: Sat May 06, 2017 11:25 am
Contact:

Providing a useful message for startup errors

Post by Coppermine »

I recall once when I installed a mod and tried to launch Factorio I got an error from that mod during startup (the data*.lua phases) from that mod along the lines of "I noticed you have this other incompatible mod installed; you shouldn't use us both at the same time".

That was very helpful. Now I find myself wanting to do the same with a mod of my own -- that is, provide a useful error message when I detect a fatal configuration issue during startup, and thus pre-empt a load failure with a less useful error that would otherwise occur.

Unfortunately I can't remember in which mod I originally saw this feature, and I can't find anything that would achieve this in the documentation (it's entirely possible I just missed it). Can anyone suggest how to do it?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Providing a useful message for startup errors

Post by darkfrei »

Just adding to info.json

Code: Select all

"dependencies": [
  "base >= 0.15.0",
"  ? mod_name < 0.0.0"
- negative version is not exists, incompatible.

Coppermine
Long Handed Inserter
Long Handed Inserter
Posts: 79
Joined: Sat May 06, 2017 11:25 am
Contact:

Re: Providing a useful message for startup errors

Post by Coppermine »

Thanks, but the mod incompatibility was just an example. My situation is more complex than that; I need to be able to run arbitrary code in data*.lua and report an error if I detect a problem.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Providing a useful message for startup errors

Post by posila »

In data*.lua you can call error("there seems to be a problem")

Coppermine
Long Handed Inserter
Long Handed Inserter
Posts: 79
Joined: Sat May 06, 2017 11:25 am
Contact:

Re: Providing a useful message for startup errors

Post by Coppermine »

posila wrote:In data*.lua you can call error("there seems to be a problem")
Perfect! Thanks :D.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13210
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Providing a useful message for startup errors

Post by Rseding91 »

0.16 also adds incompatible dependencies so in 0.16 you can do this:

Code: Select all

"dependencies": [
"base >= 0.15.0",
"! mod_name"]
and it will trigger your mod to simply be disabled at startup until the given mod is either removed or disabled.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”