change minetest.conf paraeters from a mod?
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
change minetest.conf paraeters from a mod?
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.
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.
- 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?
https://github.com/minetest/minetest/bl ... .txt#L6060
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course
Check out my website, and brand new Minetest Modding Course
- 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?
A mod should not change global settings.
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
Re: change minetest.conf paraeters from a mod?
thanks nathan.
linuxdirk - what should i be wary of when doing so?
linuxdirk - what should i be wary of when doing so?
- 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?
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.ErrorNull wrote:linuxdirk - what should i be wary of when doing so?
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)
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
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)
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
Re: change minetest.conf paraeters from a mod?
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?
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?
- 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?
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.ErrorNull wrote:just for my better understanding, what's the underlying principle for this?
Mods (or generally speaking, all applications) should not mess with user settings if not explicitly requested by the user. This is just bad behavior.
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
Re: change minetest.conf paraeters from a mod?
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.
-
- Member
- Posts: 167
- Joined: Mon May 22, 2017 20:27
Re: change minetest.conf paraeters from a mod?
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).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.
- 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?
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.micheal65536 wrote:TRWTF is Minetest not having per-world settings
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).
- ErrorNull
- Member
- Posts: 274
- Joined: Thu Mar 03, 2016 00:43
- GitHub: ErrorNull0
Re: change minetest.conf paraeters from a mod?
Linuxdirk - interesting. what function do work with "worldname/_modname/modname.conf" in regards to manipulating settings like "time_speed" during run time?
- 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?
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.)ErrorNull wrote:Linuxdirk - interesting. what function do work with "worldname/_modname/modname.conf" in regards to manipulating settings like "time_speed" during run time?
worldname/_modname/config.lua:
Code: Select all
return {
my_value = 1,
another_value = 'foo',
bla = { a = 'blub', b = 'value b' }
}
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')
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.
Who is online
Users browsing this forum: No registered users and 9 guests