EDIT: I've edited this post to contain some information from the posts below, because it is pinned at the factorio discord modding channel.
EDIT2: Rseding has now updated the main post at
viewtopic.php?p=207275#p207275 with official documentation
So, I did this:
Code: Select all
folk@--:~/Programs/factorio/bin/x64$ strings factorio | grep settings
And got lots of stuff, including this:
Code: Select all
bool-setting
double-setting
int-setting
string-setting
...
settings.lua
settings-updates.lua
settings-final-fixes.lua
So it seems they added an entirely new pre-data stage, and I have confirmed it.
Here is snipped stdout, you can see the settings-stage is before data:
Code: Select all
0.132 Create display on adapter 0. Size 1548x870 at position [176, 147].
0.472 Initialised OpenGL:[0] GeForce GTX 680/PCIe/SSE2; driver: 4.5.0 NVIDIA 378.13
0.473 Video memory size (dedicated/total available/current available): 2048/2048/1703 MB
0.493 Graphics options: [Graphics quality: normal] [Video memory usage: high] [Light scale: 25%] [DXT: auto]
0.618 Loading mod settings folk-fill 0.1.2 (settings.lua)
0.620 Loading mod core 0.0.0 (data.lua)
0.627 Loading mod base 0.15.1 (data.lua)
I added a file called settings.lua to my mod:
Code: Select all
data:extend({
{
type = "int-setting",
name = "folk-fill-std-stack-size",
setting_type = "runtime-per-user",
default_value = 25,
maximum_value = 100,
minimum_value = -20,
per_user = true,
},
{
type = "bool-setting",
name = "folk-fill-std-stack-test",
setting_type = "runtime-per-user",
default_value = true,
per_user = true,
},
{
type = "double-setting",
name = "folk-fill-std-stack-test2",
setting_type = "runtime-per-user",
default_value = -23,
per_user = true,
},
{
type = "string-setting",
name = "folk-fill-std-stack-test3",
setting_type = "runtime-per-user",
default_value = "Hello",
allowed_values = {"Hello", "foo", "bar"},
per_user = true,
},
})
Valid setting types are "runtime-per-user", "runtime-global", and "startup".
The double-setting type crashes the game to desktop when you try to edit it ingame if the game can't parse what the player inputs as a number. (fixed next patch after 0.15.1)
The int-setting type does not crash like this.
To read these things in control.lua, it looks to me like:
Code: Select all
settings.get_player_settings(game.players[event.player_index])
Returns a table containing the settings as they were when you invoked it, here is the return through serpent.block:
Code: Select all
{
nil,
nil,
nil,
nil,
["folk-fill-std-stack-size"] = {
value = 13
} --[[table: 0x00007fd020003b50]],
["folk-fill-std-stack-test"] = {
value = true
} --[[table: 0x00007fd023dfbda0]],
["folk-fill-std-stack-test2"] = {
value = -23
} --[[table: 0x00007fd02000fa40]],
["folk-fill-std-stack-test3"] = {
value = "what does the fox say"
} --[[table: 0x00007fd02000def0]]
} --[[table: 0x00007fd0352b4a90]]
While, for the data stage, and defaults
Code: Select all
print(serpent.block(settings.player))
seems to yield the default settings:
Code: Select all
{
nil,
nil,
nil,
nil,
["folk-fill-std-stack-size"] = {
value = 25
} --[[table: 0x00007fd023df1700]],
["folk-fill-std-stack-test"] = {
value = true
} --[[table: 0x00007fd023def3e0]],
["folk-fill-std-stack-test2"] = {
value = -23
} --[[table: 0x00007fd0352908c0]],
["folk-fill-std-stack-test3"] = {
value = "Hello"
} --[[table: 0x00007fd023dba5a0]]
}
And don't forget
http://lua-api.factorio.com/latest/even ... ng_changed
To get pretty locale strings for things, put this in your locale cfg
Code: Select all
[mod-setting-name]
folk-fill-std-stack-size= Stack size
[mod-setting-description]
folk-fill-std-stack-size=Default stack size to insert into placed entities inventories.\n\nNote: This is in percentage of default stack size. Setting this to 100 will insert a full stack, setting it to 25 will insert 1/4th of a stack.\n\nMinimum: 5% / Maximum 100%
Please note the extra space after the = in mod-setting-name, because the alignment of the UI elements in the mod options box are fubar. You should probably use two spaces, actually. This is also fixed first release after 0.15.1.
I've implemented two options for my mod
https://mods.factorio.com/mods/folk/folk-fill if you need more code to look at.