Can we please have an engine that reads modoptions.lua?

Can we please have an engine that reads modoptions.lua?

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14408
Joined: 17 Nov 2005, 02:43

Can we please have an engine that reads modoptions.lua?

Post by Forboding Angel » 03 May 2018, 06:32

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?
0 x

sprunk
Posts: 79
Joined: 29 Jun 2015, 07:36

Re: Can we please have an engine that reads modoptions.lua?

Post by sprunk » 03 May 2018, 09:02

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
1 x

User avatar
Silentwings
Moderator
Posts: 3433
Joined: 25 Oct 2008, 00:23

Re: Can we please have an engine that reads modoptions.lua?

Post by Silentwings » 03 May 2018, 09:26

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".
1 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7003
Joined: 16 Nov 2004, 13:08

Re: Can we please have an engine that reads modoptions.lua?

Post by zwzsg » 04 May 2018, 00:55

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".
1 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14408
Joined: 17 Nov 2005, 02:43

Re: Can we please have an engine that reads modoptions.lua?

Post by Forboding Angel » 04 May 2018, 04:21

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.
That is awful reasoning.
zwzsg wrote:And anyway, using default values without modoptions.lua decoding is easy.
I highly doubt that you use more than an even tiny amount of modoptions.

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.
1 x

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7003
Joined: 16 Nov 2004, 13:08

Re: Can we please have an engine that reads modoptions.lua?

Post by zwzsg » 05 May 2018, 13:24

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.
0 x

User avatar
Silentwings
Moderator
Posts: 3433
Joined: 25 Oct 2008, 00:23

Re: Can we please have an engine that reads modoptions.lua?

Post by Silentwings » 05 May 2018, 14:06

Having a different result when you run the game without a lobby as opposed to running WITH a lobby is terrible
Except, this isn't a proper description of what happens.

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.
forcing use to do tons of redundant checking
No. There is a choice: 12 lines of easy, game agnostic, lua, once.
I am well aware
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.
1 x

User avatar
AF
AI Developer
Posts: 20667
Joined: 14 Sep 2004, 11:32

Re: Can we please have an engine that reads modoptions.lua?

Post by AF » 18 May 2018, 03:40

Without that it would be too hard to detect when it's launched outside a lobby.
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 hack
0 x

Post Reply

Return to “Feature Requests”