How do mod options work?

How do mod options work?

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

How do mod options work?

Post by KDR_11k »

The SVN TASClient has a mod options tab in the battle screen, how can a mod use those?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Okay, figured it out with a LOT of help. To spare others the experience:

1. The Lobby-side definition is done with a file called ModOptions.lua in the mod's root dir. Specs for the content are here
2. The mod-side handling is done with Spring.GetModOptions(), it returns a table with string keys and values. Note that bools are expressed as "0" and "1".
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Post by Pxtl »

Wow, that's really cool. If only the Spring website had some sort of user-editable pages that we could use to keep track of this information, that modders, developers, and players could keep up-to-date with recent developments in the Spring engine.

/sarcasm.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Pxtl wrote:Wow, that's really cool. If only the Spring website had some sort of user-editable pages that we could use to keep track of this information, that modders, developers, and players could keep up-to-date with recent developments in the Spring engine.

/sarcasm.
I'd need an account for that...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

I have a working account, just send whatever you've got to me... I don't mess with the Wiki much, but I can do so.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Meh, if I felt like writing a proper Wiki article I'd get an account myself. In the forums I was able to post this in two sentences :P
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

GTFO 10q

Wouldn't it be a good idea to put the Lua in the SVN? Actually, it would be a good idea to centralize all of the GPL'ed Luas somewhere so people don't have to look in 128937 different places.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Post by Pxtl »

Hey, does this mean that the "ONS" mode in KP could be made into a checkbox instead of a new gametype?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Most likely.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

Could someone take the tiem to explain how to use this?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Make a ModOptions.lua file as outlined above, the settings can be retrieved using Spring.GetModOptions(). You just have to make your lua react to the settings.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

Pardon me for saying... That's as clear as mud.

If something is going to be (for the most part) required, you have to kinda spell it out for people who don't understand lua.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

You can't do this without Lua so if you don't know Lua that's not gonna help you anyway. It's not required, just pretty damn useful.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

Is it so detailed that It could not be explained?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

What else should I explain? I told you how to make the file and I told you how to read what the user inputted, the only step further I can imagine is telling you exactly how to implement your mod options.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

KDR_11k wrote:...the only step further I can imagine is telling you exactly how to implement your mod options.
That would be wonderful, if you could explain generically so that people other than myself could benefit as well.

I have messed around with it some, but from what I've seen I haven't really affected anything.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Generically?

1. Write a gadget that looks for one or more mod options.
2. Make it do what you want those mod options to do.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

OK I apologize, cause I need to be mroe clear with what I'm saying.

There are all these lists, which seem to have mix and match values. If each list was set up the same then it would make mroe sense...


for example:

{
key = 'deployment',
name = 'Deployment Mode',
desc = 'Players deploy a limited number of units before the game starts',
type = 'bool',
def = false,
},

{
key = 'ai_bonus',
name = 'AI Bonus',
desc = 'Higher numbers mean that the AI gets more resources, health, etc...',
type = 'number',
def = 1.25,
min = 0.25,
max = 10,
step = 0.05, -- quantization is aligned to the def value
-- (step <= 0) means that there is no quantization
},

{
key = 'string_opt',
name = 'String Option',
desc = 'an unused string option',
type = 'string',
def = 'BiteMe',
maxlen = 12,
},

None of these really seem to share much in common.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

Oh, so this is a thing for a gadget to interface with, not spring directly?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Yes. Spring itself doesn't care what your mod options are, you need Lua to do anything with them.

The entries there have a lot in common, the differences are for different value types. The first one's a simple checkbox, the second a slider and the third a text entry field.
Post Reply

Return to “Engine”