[0.15] Mod setting/config interface - give your input

Place to post guides, observations, things related to modding that are not mods themselves.
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

Rseding91 wrote:"double-player-health" is a way to identify this setting. This is required to be unique per-mod.
I know that info is outdated, but I wanted to point out that it seems like settings require globally unique names now? When I query a setting I don't have to specify which mod it belongs to. This seems like a bad idea that's going to cause problems with conflicting names. Maybe settings should be segregated per mod and queryable that way?
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

I notice that if I set a "double" setting to an integer value, it displays as the integer. If the default for a double setting is an integer value, the user might never realize it can be non-integer.

Suggestion: double values always display with a trailing ".0" for integer values
Rseding91
Factorio Staff
Factorio Staff
Posts: 14338
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Rseding91 »

sparr wrote:
Rseding91 wrote:"double-player-health" is a way to identify this setting. This is required to be unique per-mod.
I know that info is outdated, but I wanted to point out that it seems like settings require globally unique names now? When I query a setting I don't have to specify which mod it belongs to. This seems like a bad idea that's going to cause problems with conflicting names. Maybe settings should be segregated per mod and queryable that way?
Nothing else in the game is split per-mod: entities, items, fluids, and so on. Making them split per mod was going to quadruple or more the complexity to implement the settings so I decided against it.

Simply prefix your settings with some unique identifier for your mod and it works fine.
If you want to get ahold of me I'm almost always on Discord.
Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Supercheese »

Rseding91 wrote:It's a core part of how the entire prototype system works in Factorio. If you don't know that it exists then you probably haven't been doing anything with modding in Factorio :P
The only "documentation" that exists for Factorio prototypes is "copy the base game definitions". Since the test mod that contains the only base example of mod-settings does not contain an instance of the "order" property, you'll have to excuse me for not immediately assuming its existence as a valid property.
User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 129
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by ZlovreD »

Another gui bug:
Double scroll for settings and for GUI container
screenshot
So my suggestion to add mod list and limit max height looks more valuable. ;)
swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by swni »

Lack of documentation has been a problem but thankfully folk's work was enough to get me started, although I still have some questions. So far this is what I've figured out (partially from what other people have said and partially from experimentation):

Settings are created by extending data.raw. Use data:extend{<Setting1>, <Setting2>, ..., <SettingN>} where each <Setting> is a lua table with some of the following keys: type, name, setting_type, default_value, minimum_value, maximum_value, order, allowed_values, per_user.

"type" should be one of "int-setting", "bool-setting", "double-setting", or "string-setting".

"name" should be a string unique across all mods. This name is used in the locale configuration, and to retrieve the setting's value as described below.

"setting_type" should be "startup", "runtime-global", or "runtime-per-user".

"allowed_values" a list of values, and can be used with string and int types to make a drop down menu

"per_user" is a bool; best guess is it doesn't do anything (i.e., don't use it)


"startup" settings are accessible only in data.lua, and not in control.lua. They are accessed with settings.startup[<SettingName>].value. (Of course, one can use data.lua to copy the startup settings into a dummy entity to make the startup settings visible from control.lua, using the same trick as sparr's "Expose data.raw" mod that makes data.raw visible within control.lua.) startup has nothing to do with a new game starting as I had assumed at first, but refers to the Factorio binary starting. Changing startup settings causes Factorio to restart.

"runtime-per-user" and "runtime-global" settings are accessible only in control.lua and not in data.lua. The former are accessed with settings.global[<SettingName>].value, and the latter with settings.get_player_settings(<LuaPlayer>)[<SettingName>].value.

Locale configuration for "[mod-setting-name]" controls the label for the gui element visible to the user when choosing the value for the setting, and "[mod-setting-description]" controls the tooltip.

I'm fairly sure that if you load a saved game with different settings than it was saved with, the new settings are used and old ones forgotten, although I haven't tested this carefully. This makes it a bit tricky to have different saves going with different settings, but not any trickier than it was before. I haven't had a chance to see what happens if you try to join a multiplayer game with different settings; I assume local settings are changed to agree with the server and, if that includes startup settings, a restart is triggered.

So that leaves me with two main questions: How do you access runtime-global settings, and what does the per_user option do?
Last edited by swni on Thu Apr 27, 2017 11:26 pm, edited 1 time in total.
swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by swni »

Supercheese wrote:
Rseding91 wrote:It's a core part of how the entire prototype system works in Factorio. If you don't know that it exists then you probably haven't been doing anything with modding in Factorio :P
The only "documentation" that exists for Factorio prototypes is "copy the base game definitions". Since the test mod that contains the only base example of mod-settings does not contain an instance of the "order" property, you'll have to excuse me for not immediately assuming its existence as a valid property.
Yeah, and since most of my modding didn't involve touching prototypes it was a long time before I knew about the "order" property anyhow. By the way, where did you find the test mod? The only example I've been working off of is folk's.
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

swni wrote:So that leaves me with two main questions: How do you access runtime-global settings, and what does the per_user option do?

Code: Select all

settings.global['name_of_setting'].value
My guess is that per_user is obsolete and was part of the first attempt to do things described in the first post in this thread, and has been deprecated by the two different runtime setting types.
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

swni wrote:By the way, where did you find the test mod? The only example I've been working off of is folk's.
Test mod is only packaged with some versions of Factorio. It's in the program directory (where data/base and data/core live) under tests/mods or similar. I don't have it, because it's not packaged with the OSX Steam version of the game. Some folks elsewhere linked a zip for it.
swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by swni »

Thanks much for the quick and clear answers. Yeah, I don't have the test mod either (linux). I'll edit my post so that I can use it as a reference for myself, in lieu of documentation existing elsewhere.
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

It would be awesome if the 3-4 people in this thread who are slowly reverse engineering how the settings stuff works would collaboratively edit a wiki page.

https://wiki.factorio.com/
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Optera »

swni wrote:Lack of documentation has been a problem but thankfully folk's work was enough to get me started, although I still have some questions. So far this is what I've figured out (partially from what other people have said and partially from experimentation):

Settings are created by extending data.raw. Use data:extend{<Setting1>, <Setting2>, ..., <SettingN>} where each <Setting> is a lua table with some of the following keys: type, name, setting_type, default_value, minimum_value, maximum_value, order, allowed_values, per_user.

"type" should be one of "int-setting", "bool-setting", "double-setting", or "string-setting".

"name" should be a string unique across all mods. This name is used in the locale configuration, and to retrieve the setting's value as described below.

"setting_type" should be "startup", "runtime-global", or "runtime-per-user".

"allowed_values" a list of values, and can be used with string and int types to make a drop down menu

"per_user" is a bool; best guess is it doesn't do anything (i.e., don't use it)


"startup" settings are accessible only in data.lua, and not in control.lua. They are accessed with settings.startup[<SettingName>].value. (Of course, one can use data.lua to copy the startup settings into a dummy entity to make the startup settings visible from control.lua, using the same trick as sparr's "Expose data.raw" mod that makes data.raw visible within control.lua.) startup has nothing to do with a new game starting as I had assumed at first, but refers to the Factorio binary starting. Changing startup settings causes Factorio to restart.

"runtime-per-user" and "runtime-global" settings are accessible only in control.lua and not in data.lua. The former are accessed with settings.global[<SettingName>].value, and the latter with settings.get_player_settings(<LuaPlayer>)[<SettingName>].value.

Locale configuration for "[mod-setting-name]" controls the label for the gui element visible to the user when choosing the value for the setting, and "[mod-setting-description]" controls the tooltip.

I'm fairly sure that if you load a saved game with different settings than it was saved with, the new settings are used and old ones forgotten, although I haven't tested this carefully. This makes it a bit tricky to have different saves going with different settings, but not any trickier than it was before. I haven't had a chance to see what happens if you try to join a multiplayer game with different settings; I assume local settings are changed to agree with the server and, if that includes startup settings, a restart is triggered.

So that leaves me with two main questions: How do you access runtime-global settings, and what does the per_user option do?
You forgot 3 extremely useful parameters:sry overlooked you mentioning them briefly.

"default_value" - default value sets a default for int, double, string and bool

"maximum_value" - maximum allowed value for int and double

"minimum_value" - minimum allowed value for int and double

I'm curious what per_user does myself.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Nexela »

I think per_user means any user can change their user_runtime setting. Whereas if it is false only admin can change??? Haven't tested these with MP yet but I may soon :)
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Optera »

Nexela wrote:I think per_user means any user can change their user_runtime setting. Whereas if it is false only admin can change??? Haven't tested these with MP yet but I may soon :)
Only Admins can change settings regardless of per_user.

Any Idea why changing global settings in MP keeps crashing the host with "Attempting to save empty mod settings."?
viewtopic.php?f=7&t=45395
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Nexela »

runtime-per-user can be changed by users
runtime-global by admins
startup by anyone before world loads, if your startup doesn't you will be prompted to restart with those settings

So back to not having any clue what the per_user variable does
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Nexela »

swni wrote: "startup" settings are accessible only in data.lua, and not in control.lua. They are accessed with settings.startup[<SettingName>].value. (Of course, one can use data.lua to copy the startup settings into a dummy entity to make the startup settings visible from control.lua, using the same trick as sparr's "Expose data.raw" mod that makes data.raw visible within control.lua.) startup has nothing to do with a new game starting as I had assumed at first, but refers to the Factorio binary starting. Changing startup settings causes Factorio to restart.
Startup settings are available for reading in control.lua without any fancery

/c game.print(settings.startup["picker-unminable-logistic-robots"].value)
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Nexela »

@rseding91

When joining an MP game with different startup settings it has you restart with those settings enabled. Any chance you could put it on your todo list to make this a temporary change where the next restart afterwards will revert to what they were before?
User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 129
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by ZlovreD »

Idea:
Add chain activation and new field: prerequisites = {name, condition}.

In other words - if some settings need some prerequisites before they can be used like techs.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14338
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by Rseding91 »

Nexela wrote:runtime-per-user can be changed by users
runtime-global by admins
startup by anyone before world loads, if your startup doesn't you will be prompted to restart with those settings

So back to not having any clue what the per_user variable does
Where did "per_user" come from? It's not used in any context when it comes to mod settings.

As for documentation: I'll finish when I've got today and put it in the main post.
If you want to get ahold of me I'm almost always on Discord.
sparr
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [0.15] Mod setting/config interface - give your input

Post by sparr »

Rseding91 wrote:Where did "per_user" come from? It's not used in any context when it comes to mod settings.
Artifact of people trying to follow the original not-really-documentation from this thread, and a bunch of examples based on that.
Post Reply

Return to “Modding discussion”