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

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 112
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

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

Post by ZlovreD » Wed Apr 26, 2017 12:57 pm

swni wrote:What is the difference between startup, runtime-global, and runtime-per-user? E.g., which ones are accessible where (such as control.lua and data.lua). If a user changes a setting from the main menu (i.e., there is no game running), and then loads a game, does the loaded game see the old values for the settings or the new values? (I assume "startup" means it only changes new games, whereas runtime means it also changes existing games.) If a user changes a setting from within a game, and then loads a different game, what happens?
Check first post for details. In short - 'startup' if you need make changes in data.raw; runtime-global - if you want that only admin can could make changes when game is active game (change game speed for example); runtime-per-user - independed for any player in multiplayer mode (change player color).
swni wrote:Specifically I'm interested in settings for a mod that affects map generation, so I'm assuming "startup" is most suitable for that use case.
Yep. Also you can make your onw pressets for map generation:

Code: Select all

data.raw['map-gen-presets'].default["rich-resources"] =
    {
      order = "b",
      basic_settings =
      {
        autoplace_controls =
        {
          ["iron-ore"] = { richness = "very-good"},
          ["copper-ore"] = { richness = "very-good"},
          ["stone"] = { richness = "very-good"},
          ["coal"] = { richness = "very-good"},
          ["uranium-ore"] = { richness = "very-good"},
          ["crude-oil"] = { richness = "very-good"}
        }
      }
    }
swni wrote:What is the lua interface for reading the settings? I am aware of settings.get_player_settings(<LuaPlayer>)[<SettingName>].value but when I tried to dump the "settings" table to see what other interface options there might be I didn't see any. (I guess it's all hidden behind a metatable.)
for startap settings:

Code: Select all

local var = settings.startup.['settings-name']
for runtime (in-game) settings (folk's post):

Code: Select all

local var = settings.get_player_settings(game.players[event.player_index])['settings-name']
swni wrote:I noticed that setting names are global across all mods. That's a bit inconvenient, because it forces the use of really long setting names to avoid accidentally clobbering someone else's mod. It would be nice if settings where namespaced by mod, and perhaps by default you only see your own mod's settings, but there was a way to examine settings belonging to another namespace if for whatever obscure reason you needed to look up the settings for another mod. (I don't plan on it myself.)
Even base/core mod data is not protected from overriding. So this needs to change it everywhere or keep it as is, or continue to use unique prefixes, imo.
swni wrote:Finally, not really a question about the new interface, but my mod takes arbitrary lua code as part of its configuration... any suggestions from anyone on how to make that less painful on the user? I was thinking of providing several preset configurations in a drop-down box with an option for falling back to config.lua in case the user wanted the full customizability.
I'm assume what mod-config system was developed more likely as global trigger system, not making it as 'one place' for every mod settings. So keep make your own in-game gui configs for detailed calibration and 'mod-settings' for user's global dessisions how your calibration will work in game or what it could include.

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 1:31 am

Why do some of the keys in settings.json have dashes/hyphens and some have underscores in their name?

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 2:16 am

I can't get factorio to recognize my settings.json file. My mod is loaded, but options>mods says no mods have options.

Code: Select all

{
  "pollution_intensity":
    {
      "type": "runtime",
      "data_type": "double",
      "default_value": 1.0,
      "per_user": false,
      "admin": true,
      "name-key": "pollution_intensity",
      "description-key": "pollution_intensity"
    }
  ,
  "medium_spill_threshold":
    {
      "type": "runtime",
      "data_type": "int",
      "default_value": 100,
      "per_user": false,
      "admin": true,
      "name-key": "medium_spill_threshold",
      "description-key": "medium_spill_threshold"
    }
  ,
  "large_spill_threshold":
    {
      "type": "runtime",
      "data_type": "int",
      "default_value": 1000,
      "per_user": false,
      "admin": true,
      "name-key": "large_spill_threshold",
      "description-key": "large_spill_threshold"
    }
}

User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 112
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

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

Post by ZlovreD » Thu Apr 27, 2017 2:38 am

Suggestions for enhancement:
  • add a list of mods on side to select which one settings to display
    set the limit of height of settings gui (scrolls)
    slider for numeric values as an additional to the text field
    the addition field for a numerical prototype: display_style = "digits / slider / both"

User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 112
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

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

Post by ZlovreD » Thu Apr 27, 2017 2:39 am

sparr wrote:I can't get factorio to recognize my settings.json file. My mod is loaded, but options>mods says no mods have options.
viewtopic.php?f=34&t=32890&start=40#p258222
and/or settings.lua:

Code: Select all

data:extend({
	{
		type = "bool-setting",
		name = "name-test1",
		setting_type = "startup",
		default_value = true
	},
	{
		type = "string-setting",
		name = "name-test2",
		setting_type = "runtime-per-user",
		default_value = "Hello",
		allowed_values = {"Hello", "foo", "bar"},
	}
})

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 2:47 am

ZlovreD wrote:viewtopic.php?f=34&t=32890&start=40#p258222
and/or settings.lua
That's a hackish reverse engineered method. I'd really rather know the official process, so that I can converge on a real solution rather than releasing something that just happens to work today but breaks and has to be completely replaced in 0.15.3.

Nexela
Smart Inserter
Smart Inserter
Posts: 1816
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post by Nexela » Thu Apr 27, 2017 3:59 am

That is the way to do it

create your settings in settings.lua
reference your settings using the settings global variable in data or control stages

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 4:23 am

I think it's a Bad Idea to use data injection methods gleaned from reverse engineering strings out of the game binary, especially when that contradicts what we've been told by a dev. I'll just wait for official documentation.

Nexela
Smart Inserter
Smart Inserter
Posts: 1816
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post by Nexela » Thu Apr 27, 2017 4:37 am

Checkout factorio install folder \tests\mods\test_mod_1.0.0 For Official examples of how to create them

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 4:40 am

Nexela wrote:factorio install folder \tests\mods\test_mod_1.0.0
Doesn't seem to exist on mac steam 0.15. Is it posted online anywhere?

Nexela
Smart Inserter
Smart Inserter
Posts: 1816
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post by Nexela » Thu Apr 27, 2017 4:50 am

Might be only packaged with the .zip version at factorio.com

It doesn't show the API calls (those are available on the API page http://lua-api.factorio.com/0.15.2/) but it does show creation/and locale
Attachments
test_mod_1.0.0.zip
(17.9 KiB) Downloaded 29 times
Last edited by Nexela on Thu Apr 27, 2017 4:51 am, edited 1 time in total.

catalyst518
Inserter
Inserter
Posts: 35
Joined: Thu Apr 14, 2016 2:01 am
Contact:

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

Post by catalyst518 » Thu Apr 27, 2017 4:51 am

Here are the relevant files from the Windows zip file.


Factorio_0.15.2\tests\mods\test_mod_1.0.0\settings.lua

Code: Select all

data:extend({
  {
    type = "int-setting",
    name = "setting-1",
    setting_type = "runtime-per-user",
    default_value = 112
  },
  {
    type = "double-setting",
    name = "setting-2",
    setting_type = "runtime-global",
    default_value = 100,
    minimum_value = -20,
    maximum_value = 5000
  }
})
Factorio_0.15.2\tests\mods\test_mod_1.0.0\locale\en\mod-setting-names.cfg

Code: Select all

[mod-setting-name]
setting-1=Setting 1
setting-2=Setting 2

[mod-setting-description]
setting-1=Setting 1 description
setting-2=Setting 2 description

sparr
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

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

Post by sparr » Thu Apr 27, 2017 5:29 am

Thanks for posting that. I'm sad to see the top of the thread is no longer accurate; I wasted time following it :(

That said, on to bigger and better questions!

in my on_tick handler, event.player_index is nil. how do I get a global setting when I don't have a specific player to query against?

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

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

Post by Rseding91 » Thu Apr 27, 2017 5:40 am

sparr wrote:Thanks for posting that. I'm sad to see the top of the thread is no longer accurate; I wasted time following it :(

That said, on to bigger and better questions!

in my on_tick handler, event.player_index is nil. how do I get a global setting when I don't have a specific player to query against?
"top of the thread"?

Also you access global settings using the "settings" global. If you want settings for a specific player then you use that players index or you iterate all players and do what ever you'd like to do with them.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2289
Joined: Sat Jun 11, 2016 6:41 am
Contact:

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

Post by Optera » Thu Apr 27, 2017 2:53 pm

Sorting settings by their strings forces me to use pretty silly key names as i want my settings to be grouped thematically.
"modname-sorting-parameter"
Edit: i misinterpreted my earlier tests. It sorts by strings AFTER localization so every language sees the options in a different order.
An order property like in item prototypes would be appreciated.

Subgroups would be the cherry on top, but only very few mods would have enough settings to warrant those.

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

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

Post by Rseding91 » Thu Apr 27, 2017 4:53 pm

Optera wrote:Sorting settings by their strings forces me to use pretty silly key names as i want my settings to be grouped thematically.
"modname-sorting-parameter"
Edit: i misinterpreted my earlier tests. It sorts by strings AFTER localization so every language sees the options in a different order.
An order property like in item prototypes would be appreciated.

Subgroups would be the cherry on top, but only very few mods would have enough settings to warrant those.
Mod settings are sorted (in the display) like this:
  • First by mod
  • Then by "order" (order string)
  • Then by localized name
  • then by prototype name
I'll remove the localized name part since it probably adds more confusion than it helps visually.
If you want to get ahold of me I'm almost always on Discord.

Supercheese
Filter Inserter
Filter Inserter
Posts: 835
Joined: Mon Sep 14, 2015 7:40 am
Contact:

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

Post by Supercheese » Thu Apr 27, 2017 6:45 pm

Oh, so there is an "order" property that can be set? It's impossible to know such things without documentation...

wormmus
Inserter
Inserter
Posts: 27
Joined: Tue Nov 17, 2015 11:01 pm
Contact:

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

Post by wormmus » Thu Apr 27, 2017 7:44 pm

Is it possible to have some way of sorting the options that a mod provides?

0.15.2 allowed in the locale file:
[A] Blah
Blah
[C] Blah

0.15.3...I haven't figured out how it sorts them but it now ignores the [A] [C].

UPDATE:
Apparently now it sorts the mod-setting-name.

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

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

Post by Rseding91 » Thu Apr 27, 2017 8:14 pm

Supercheese wrote:Oh, so there is an "order" property that can be set? It's impossible to know such things without documentation...
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
If you want to get ahold of me I'm almost always on Discord.

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

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

Post by Rseding91 » Thu Apr 27, 2017 8:15 pm

wormmus wrote:Is it possible to have some way of sorting the options that a mod provides?

0.15.2 allowed in the locale file:
[A] Blah
Blah
[C] Blah

0.15.3...I haven't figured out how it sorts them but it now ignores the [A] [C].

UPDATE:
Apparently now it sorts the mod-setting-name.


No, it sorts how I said it sorts 2 posts before yours :P -> posting.php?mode=quote&f=34&p=260819#pr260664
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding discussion”

Who is online

Users browsing this forum: No registered users