# I want to make a moddable game. How does this affect my programming language choice? [closed]

I have been getting started making some small games in Java, and I am considering learning C# for a bigger project. I would very much like to make a moddable game, but someone told me that I need to stick with Java if I want the game to be moddable, though I don't understand why.

So, what programming language characteristics make a language more suited to moddable games?

• If you want to make a moddable game, PhysicsFS might be a very useful library to know about. (It has nothing to do with physics, don't let the name fool you. :) ) – Paul Manta Jan 3 '12 at 14:30
• "but someone told me that I need to stick with Java if I want the game to be moddable" This, by the way, is BS. – Ray Dey Jan 3 '12 at 19:11

It depends on how you want to design your mod system. I'll explore two of them.

# SDK

Most likely you will require that your modders use the same language as you do, and load up mods via reflection (or similar, depending on your language of choice). This will obviously limit you to languages which can do late binding - and there are a good many that can do this (even C can do late binding with some clever LoadLibrary trickery). You could even do some meta-modding, where a mod could host other mods (e.g. scripted mods).

The first problem with this approach is hiding internal state. Taking C# for example a modder could simply use reflection to access private members, C can also do this (although more effort is required).

The second problem is hosting. People don't really like foreign code running on their system with no sandbox in place. As a worst-case scenario you could write a mod that sets up a seedbox; if this was installed at an ISP it could do some serious harm to their reputation.

# Scripting

Modders would use a language such as Lua to create mods. You would either require a language that could invoke native code (to interface with Lua); or you would have to write your own scripting language in your language of choice.

The first problem here is that most scripting languages are interpreted, which may not be acceptable for real-time systems (although, see LuaJIT); such as games.

Ironically the second problem still exists here; taking Lua as an example I was extremely disappointed that is has 'shelling-out' functions included in the core/default library - making it entirely useless as a sandboxed environment (without a large amount of effort, luck and maintenance), it's hard to portray how angry I am about this, but I really hope they were drinking some strong cocktails when they included these anti-features. You could obviously easily avoid this if you rolled your own language (see: UnrealScript).

Finally the cost of interacting with a scripting engine may be prohibitive - again taking Lua as an example, combined with C#: C# has substantial overhead when invoking native functions (via P/Invoke) and Lua is quite a 'chatty' API. This could lead to problems if the way you design the 'script SDK' requires a lot of chatting between your primary language and your scripting language (note that C doesn't really have this problem). Again you could dodge this by writing your own scripting language (and in the case of C# compiling it to MSIL) and executing it in the quickest way under your [virtual] environment.

Because the script is essentially running on a completely different system to your primary code you can control the access to internal state entirely (unless they do some fancy stuff with the previously-mentioned shell functions).

# Conclusion

I did veer a bit off-topic, however, what you can basically garner from that wall of text is that you should be able to make a moddable game in any language (I would venture to say that you can) - but in some languages may lead to more work. Am I a bit anal about security? Yes, you should be too when it comes to user-code.

• In the first scenario you described, you're talking about the user actually programming his own dynamic library and plugging it into the game? I've seen this used before in libraries (e.g. audio library to add new codecs, etc) but, possibly because I've never looked too much into modding, Ive never run into a case like this for a game. I'm curious about this (since it seems really hard for the user to know how to do this and I usually see mods as being accessible) so do you know any example? Most of the time I see specialized tools, such as world editors with a bit of scripting being used. – David Gouveia Jan 3 '12 at 15:47
• @DavidGouveia I believe at least one version of the engine Paradox used for Europa Universalis (and equivalent games for different time periods) supported a form of binary patching (although it might've been by having the modder patch the source of and recompile one of the games DLLs instead of having proper SDK support) in addition to the more commonly used mod by changing a data file implementation. – Dan Is Fiddling By Firelight Jan 3 '12 at 16:20
• @DavidGouveia see: Source engine; or even Winamp plugins. I think Quake even works like this. I have garnered that you use C#; so you might want to look into MEF (Managed Extensibility Framework): expose an interface, load it up via reflection and bob's your uncle. – Jonathan Dickinson Jan 3 '12 at 20:54
• @JonathanDickinson Oh, I had no idea that the Source engine ran under this model. Always imagined a set of tools like The Elder's Scrolls Construction set. Thanks for the info (I did have an idea how it worked, just thought it might be too complicated for the general modder to use). And I really laughed at the "bob's your uncle part". :-) – David Gouveia Jan 3 '12 at 21:00
• Re Lua: These guys have a sandboxed Lua suitable for use in wiki software (and stable enough that the English Wikipedia uses it). I'm sure you could adapt it to your needs, but some parts of the extension are GPL'd so check with your lawyer. – Kevin May 13 '16 at 6:00

I'd say the language is not much of a deciding factor here, it's really just how flexible and data-driven you make your game that defines it.

Every game runs on a set of data (e.g. everything from levels, meshes, configurations, items). The difference between a normal game and a moddable game is that the later provides tools that allow the user to modify existing data (or add his own data). Whatever language you choose, just try making your game as data-driven as possible and avoid hardcoding any game content. Virtually any language you'd probably choose can read data from disk, which is most of what you need.

It's also half way there if you just create the tools for your own personal use (for instance, your own level editor) and later perfect them and share them with your users. The Super Meat Boy level editor was pretty much that, an improved verision of the tool used during the development of the game.

And depending on the type of game, you might want to allow users to script some of the game behavior. In which you case you should look into incorporating a scripting language into your game since early (either your own, or an existing one like Lua or Python which are popular choices). This also falls under the category of data-driven design. If you decide to use an existing scripting language, it might be worth checking if the programming language of your choice has bindings for that scripting language (usually in the form of 3rd party libraries).

The language you choose doesn't really determine how moddable a game is, the way you use the language matters more.

If most of your game is data driven (that is game data is defined in a file which is read from your code) the game can be very modifiable. This can be done in pretty much any language. Using a scripting language also makes it easier to mod a game.

However that does not automatically mean not using those things makes it impossible to mod a game. Minecraft for example is not a very moddable game at all, however there are pretty good decompilers available for Java and a very large community for Minecraft, so a lot of tools were made to make Minecraft moddable (various modloaders, Bukkit). With those tools it is possible to mod Minecraft (however they are, probably, technically illegal in some countries).

Best advice I can give you, is to use the tools you want modders to use; If you define a NPC from a file it can be modded, if you special case it in code it probably can't be.

Java is perfectly suitable for writing a moddable game.

Having said that, the best way to make a game moddable is usually to adopt a dynamic language that can be embedded within the broader application and used for scripting. You typically want a dynamic language because the point is to be able to interact with the code at runtime, without going through a whole compile/build/test cycle.

Some dynamic language choices to consider:

• Groovy - an excellent dynamic Java-like language that can be embedded within larger Java programs.
• Clojure - a powerful, dynamic Lisp for the JVM. Might be hard for some modders to get their head around, but is an exceptionally powerful language and can be embedded very easily. Haven't seen it used yet for game modding but no reason why not.
• Lua - a very popular game scripting language. I beleive there are versions for the JVM that you can use from within Java (although I haven't tried these myself)
• JavaScript - available on the JVM via Rhino. A pretty solid choice for game scripting as lots of people know some JavaScript, plus the prototype object model fits game mods very well.

There is a way easier way to do this in java though it's a bit sloppy. All you gotta do is take the dot java files in a folder and then put this batch file with the folder, name it Run:

javac /src/.java Java /src/

Note: You can add as many classes you want. Note: In the last line make sure NOT to put any extensions aka .java,.exe,.bat,ect.

That will basically just recompile the code every time the game is run, so if the game source is change it will compile it and then run the newly compiled game... Sadly you can't add other people's mods into the game.

• Jacob I don't think you understood the question, please read through the answers and see if that helps you understand what was being discussed here. – vikki Sep 19 '13 at 18:52