Can we please have an engine that reads modoptions.lua?
Moderator: Moderators
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Can we please have an engine that reads modoptions.lua?
Currently we have to constantly add tons of redundancy because of modoptions only being visible to spring when launched via a lobby. Can the engine be made to read modoptions.lua and the defaults within, please?
Re: Can we please have an engine that reads modoptions.lua?
Poison your `GetModOptions` calls at your lua entry points. Here's an example for filling in missing defaults, stuff like checking correctness is left as an exercise to the reader.
Code: Select all
local modOptions = Spring.GetModOptions()
do
local fileMO = VFS.Include("ModOptions.lua", VFS.MOD)
for i = 1, #fileMO do
local modopt = fileMO[i]
if not modOptions[modopt.key] then
modOptions[modopt.key] = modopt.def
end
end
end
Spring.GetModOptions = function ()
return modOptions
end
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Can we please have an engine that reads modoptions.lua?
modoptions.lua is a lua table -> the game can access it, as in Sprunks code.
When the game is started without a value passed for a modoption, it makes sense to have that modoption ==nil; if the engine didn't do this, it wouldn't be possible to detect if the modoption was being set "by the game defaults" or "by the user".
When the game is started without a value passed for a modoption, it makes sense to have that modoption ==nil; if the engine didn't do this, it wouldn't be possible to detect if the modoption was being set "by the game defaults" or "by the user".
Re: Can we please have an engine that reads modoptions.lua?
I like that the engine doesn't read the default modoptions.lua by itself. Without that it would be too hard to detect when it's launched outside a lobby.
And anyway, using default values without modoptions.lua decoding is easy.
So I strongly hope modoptions.lua remains "options lobby should display" and not "every and only options the game can ever use in its startscripts".
And anyway, using default values without modoptions.lua decoding is easy.
So I strongly hope modoptions.lua remains "options lobby should display" and not "every and only options the game can ever use in its startscripts".
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Can we please have an engine that reads modoptions.lua?
That is awful reasoning.zwzsg wrote:I like that the engine doesn't read the default modoptions.lua by itself. Without that it would be too hard to detect when it's launched outside a lobby.
I highly doubt that you use more than an even tiny amount of modoptions.zwzsg wrote:And anyway, using default values without modoptions.lua decoding is easy.
And yes... I am well aware, That does not make it a good method. Just because you can workaround something, does not then validate the method.
Having a different result when you run the game without a lobby as opposed to running WITH a lobby is terrible and should have been fixed long ago. This qualifies as a bug. The engine should always be reading options, instead of only the lobby passing options and forcing use to do tons of redundant checking in order to make sure that the game doesn't crash and burn when running outside of a lobby.
Re: Can we please have an engine that reads modoptions.lua?
I use fewer regulars modoptions, but tons of hidden modoptions (for single player).
As sprunk showed, you don't have to write code to add missing default for each individual modoptions, but can do it programmatically for all, once, with a couple lines.
As sprunk showed, you don't have to write code to add missing default for each individual modoptions, but can do it programmatically for all, once, with a couple lines.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Can we please have an engine that reads modoptions.lua?
Except, this isn't a proper description of what happens.Having a different result when you run the game without a lobby as opposed to running WITH a lobby is terrible
What does happen: If the start-script does not specify a value for a modoption, the engine records the value it was given as nil.
The engine does not know or care whether the start-script was generated by a lobby, by hand, from a repo, from Spring.Reload, from the previous start-script, etc, etc. Strictly speaking, the engine doesn't even know if it was invoked by a lobby, mouse-click, or from a command line. It might be more user friendly if the engine had an interface for specifying modoptions in the case where the engine is not given a start-script and generates one itself - but, with a dead easy way for lua to change nils to game defaults (if/when wanted, which is apparently not always), and with a future based on lua-menu anyway, writing a GUI for this inside engine code for this would be dead time.
No. There is a choice: 12 lines of easy, game agnostic, lua, once.forcing use to do tons of redundant checking
From the 85 line workaround you linked (and presumably wrote for EvoRTS) - which hardcodes a list of your modoption names and hardcodes duplicates of their default values from your modoptions.lua file - it doesn't look it.I am well aware
Re: Can we please have an engine that reads modoptions.lua?
Since we have the code to the game engine, perhaps we should modify it so that this is explicitly possible to check for, rather than using a hackWithout that it would be too hard to detect when it's launched outside a lobby.