change minetest.conf paraeters from a mod?

Post Reply
User avatar
ErrorNull
Member
Posts: 274
Joined: Thu Mar 03, 2016 00:43
GitHub: ErrorNull0

change minetest.conf paraeters from a mod?

by ErrorNull » Post

hello. is this possible? for example, i'd like to change the default minetest time from 72 to 24 from my mod.

however, seems like it can only be done via modifying the minetest.conf file:
time_speed = 24

is there a global mintest function where i can "set" time_speed to 24?

thanks everyone.

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: change minetest.conf paraeters from a mod?

by Nathan.S » Post

I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: change minetest.conf paraeters from a mod?

by Linuxdirk » Post

A mod should not change global settings.

User avatar
ErrorNull
Member
Posts: 274
Joined: Thu Mar 03, 2016 00:43
GitHub: ErrorNull0

Re: change minetest.conf paraeters from a mod?

by ErrorNull » Post

thanks nathan.

linuxdirk - what should i be wary of when doing so?

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: change minetest.conf paraeters from a mod?

by Linuxdirk » Post

ErrorNull wrote:linuxdirk - what should i be wary of when doing so?
First check if there is a better method that works without changing the configuration. If there is none store the original configuration somewhere and restore it when the server shuts down.

For your issue right here: I actually do exactly this in my timespeed mod. The minimal workflow for doing so is this:

On server start I store the time_speed value within the mod storage …

Code: Select all

minetest.after(5, function ()
    -- Having it in a minetest.after works best for me
    local storage = minetest.get_mod_storage()
    storage:set_float('timespeed_original', minetest.settings:get('time_speed'))
end)
… set the time speed as wanted …

Code: Select all

local set_timespeed = function ()
    -- Some more fancy stuff happening here before setting the speed.
    minetest.settings:set('time_speed', whatever_speed_you_want)
end
… and then set the original value when shutting down the server …

Code: Select all

minetest.register_on_shutdown(function ()
    minetest.settings:set('time_speed', storage:get_float('timespeed_original'))
    storage:set_string('timespeed_time', nil)
    storage:set_string('timespeed_original', nil)
end)
… and also clean up the mod storage because I do not need it on next server start.

User avatar
ErrorNull
Member
Posts: 274
Joined: Thu Mar 03, 2016 00:43
GitHub: ErrorNull0

Re: change minetest.conf paraeters from a mod?

by ErrorNull » Post

wow thanks much Linuxdirk for the code example. i will certainly follow this guideline when needing to modify the .conf settings.

just for my better understanding, what's the underlying principle for this? is this to prevent multiple mods from 'permanently' changing the .conf values unbeknownst to the server admin between server restarts and confusion ensues?

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: change minetest.conf paraeters from a mod?

by Linuxdirk » Post

ErrorNull wrote:just for my better understanding, what's the underlying principle for this?
The main problem with changing settings from mods is that the settings are not only applied for the current world but will also be used for other worlds or as default values for new worlds.

Mods (or generally speaking, all applications) should not mess with user settings if not explicitly requested by the user. This is just bad behavior.

User avatar
ErrorNull
Member
Posts: 274
Joined: Thu Mar 03, 2016 00:43
GitHub: ErrorNull0

Re: change minetest.conf paraeters from a mod?

by ErrorNull » Post

ah yes. totally overlooked that. we're so focused on making our mod and with thoughts of the player enjoying our creation, that we can forget that the player may need to play other sub games too.

micheal65536
Member
Posts: 167
Joined: Mon May 22, 2017 20:27

Re: change minetest.conf paraeters from a mod?

by micheal65536 » Post

Linuxdirk wrote:The main problem with changing settings from mods is that the settings are not only applied for the current world but will also be used for other worlds or as default values for new worlds.

Mods (or generally speaking, all applications) should not mess with user settings if not explicitly requested by the user. This is just bad behavior.
TRWTF is Minetest not having per-world settings (that override/replace the per-subgame settings) and per-mod settings (that are only available to a specific mod the same way that mod storage is, to prevent potential namespace conflicts or one mod messing with another mod's settings).

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: change minetest.conf paraeters from a mod?

by Linuxdirk » Post

micheal65536 wrote:TRWTF is Minetest not having per-world settings
This is the reason why I recently started storing configuration/settings on a per-world basis entirely done by mod code and manual reading/parsing of the files.

Default settings can be done in minetest.conf and those settings can be overridden on a per-world basis (./worlds/worldname/_modname/modname.conf and similar).

User avatar
ErrorNull
Member
Posts: 274
Joined: Thu Mar 03, 2016 00:43
GitHub: ErrorNull0

Re: change minetest.conf paraeters from a mod?

by ErrorNull » Post

Linuxdirk - interesting. what function do work with "worldname/_modname/modname.conf" in regards to manipulating settings like "time_speed" during run time?

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: change minetest.conf paraeters from a mod?

by Linuxdirk » Post

ErrorNull wrote:Linuxdirk - interesting. what function do work with "worldname/_modname/modname.conf" in regards to manipulating settings like "time_speed" during run time?
None. time_speed unfortunately stays a global setting. But you can store your desired default value in such a file and then load it from there. (You still need to store the original value before setting your desired value, though.)

worldname/_modname/config.lua:

Code: Select all

return {
    my_value = 1,
    another_value = 'foo',
    bla = { a = 'blub', b = 'value b' }
}
And in your mod’s code:

Code: Select all

local worldpath = minetest.get_worldpath()
local modname = minetest.get_current_modname()
local configuration = dofile(worldpath..DIR_DELIM..'_'..modname..DIR_DELIM..'config.lua')
Now configuration holds a world-specific configuration table you can use later.

Of course you need to check for errors (i.e. if the file exists) and you need to fill missing options if the player did not provide everything.

I am pretty sure you can also parse a config file in that way. But I never tried because the key-value storage is too limited for my needs.

https://github.com/minetest/minetest/bl ... 6077-L6109

But when you use this exclusively you could use world-specific configuration storage. This does not circumvent time_speed being global but you don’t need to mess with the user’s global configuration.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests