Page 6 of 11

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

Posted: Thu Apr 27, 2017 9:13 pm
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?

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

Posted: Thu Apr 27, 2017 9:14 pm
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

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

Posted: Thu Apr 27, 2017 9:15 pm
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.

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

Posted: Thu Apr 27, 2017 10:06 pm
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.

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

Posted: Thu Apr 27, 2017 10:47 pm
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. ;)

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

Posted: Thu Apr 27, 2017 10:48 pm
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?

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

Posted: Thu Apr 27, 2017 10:57 pm
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.

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

Posted: Thu Apr 27, 2017 11:14 pm
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.

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

Posted: Thu Apr 27, 2017 11:15 pm
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.

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

Posted: Thu Apr 27, 2017 11:21 pm
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.

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

Posted: Thu Apr 27, 2017 11:27 pm
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/

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

Posted: Fri Apr 28, 2017 6:25 am
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.

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

Posted: Fri Apr 28, 2017 10:43 am
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 :)

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

Posted: Fri Apr 28, 2017 10:50 am
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

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

Posted: Fri Apr 28, 2017 11:57 am
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

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

Posted: Fri Apr 28, 2017 1:05 pm
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)

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

Posted: Fri Apr 28, 2017 1:12 pm
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?

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

Posted: Fri Apr 28, 2017 1:43 pm
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.

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

Posted: Fri Apr 28, 2017 3:43 pm
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.

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

Posted: Fri Apr 28, 2017 4:27 pm
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.