In previous journals we’ve discussed the intention to create a modding layer that would use Python as its scripting language. Python is slower than Lua in terms of interpreted languages but there’s nothing stopping us from having C++ source that people could use to in addition or instead of a scripting language for performance sensitive elements of a game.
With that said, let’s hear from those familiar with both on what they think of either one and why.
I'm not familiar with both so I can't really speak up.
Can you tell us more exactly what the mod layer is, and how/if it relates to Elemental?
Edit: If I were to comment anyway, I would say the argument for LUA is it has been used extensively in other mod structures for games.
Edit2: LUA in games and Python in games (scroll down to "specific games")
I haven't used either. I do like the idea of being able to inject C++ code in there as well. I don't know C++ all too well, but I can make my way around.
I'd much rather see C# used, as that's what I use daily in my job, and I really dont have the time nor inclination to learn yet a new language.
Basically, they want to make scripting available to modders. Without exposing the source code, that means there needs to be a "wrapper" of sorts that talks to the engine, that's the mod layer. It's either Python or LUA so the modder codes in either of those, and the mod layer goes and tells the actual engine what you want it to do. The extent of the capabilities of the mod layer depends solely on how much of the engine SD wants to expose to it. For reference, I believe Civ mods are done with Python, and Supreme Commander are with LUA. Both games have pretty drastic mods.
Here is a quick comparison of the same code in a few langauges (VB code blocks will be used, as the forum does not have some of these).
Lua:
Code: vb function factorial(n) if n == 0 then return 1 else return n * factorial(n - 1) end end
Python*:
AngelScript & C++:
* In Python, the number of indents (tabs) at the start of the line matters.
Annatar11, I understand that, but is that what Frogboy is talking about - or is he talking about the "mod layer" from his roadmap? They may be two completely separate things.
Oh, I read it as one and the same.. it's probably separate from the Elemental track because in theory any game that uses the engine should be able to use the mod layer. Maybe with modifications depending on whether or not the engine advances, but in general..
Well, I don't know one way or the other. That's why I'm asking
C++
I have to say that I am interested in seeing how python would work. I am an "old" c/c++ guy so syntax either way is going to be fine with me.
Performance may end up being a larger issue than we think especially with modders writing code that isn't exactly efficient.
The advantage of supporting C++ is that it would probably open up modding to a larger community. Python is by all accounts relatively easy to learn, but there is probably a set of people who would like to do some deep modding, but just don't feel like learning yet another language.
C++ also has a very robust set of public libraries out there, so I think we'd see a large variety of mods, and a good possibility of new games created on the platform.
One final thought: if there's a way for the community to support the Lua integration, that might be a good compromise. I can understand Stardock not wanting to support a massive, diverse platform. If you can crowd-source portions of it, though, it might allow the flexibility without the support costs. Just an idea, and an admittedly uninformed one at that.
JavaScript of Classic ASP which are what I use when I'm allowed to code something.
I was trying to learn Python. Don't make me start with LUA too.
I hate Lua's implementation of OOP as it's prototype-based (like Javascript) rather than class-based (like every other language on the face of the planet), but other than that it's a pretty nice language, particularly for writing quick scripts. Still, Python is a great language in all aspects and so my vote would go for it over Lua, but my opinion ain't worth that much as I've never written a game mod in my life.
This seems like a question of whether we want to focus on small-time or big-time projects. I feel like Python would be more inviting for dabblers, but C++ would be more beneficial to big time projects.
I don't really feel like either language would be restrictive to someone who really wanted to have a go at modding, however.
C++ code is an option regardless of what other scripting language they choose if I read Frogboy's post correctly. The question is Lua vs Python.
This is the post I have been waiting for! CODE I will also preface this with the fact that I personally just BASH my way with the scripts I write...
I work with Python more than I want for webserver services, and kind of hate it. It has a huge number of valuable parsing, function, and dynamic generation libraries, but every time I need to update it or recompile, I want to buy a bottle of whiskey to nurse my battered body after I have finally won. Powerful, useful but painful. And oh sweet gods of mercy, going lib to lib trying to find the whitespace bugs!
I have not worked with Lua before, but that code snippet makes me want to. In general I think any syntactically controlled programming language is far easier for a general audience than a grammar based one; you can look at and play with pieces of the syntax, while with a grammer you really need a formal guide or trial and error insanity (IMO experience at least). Combining Lua with the tag driven XML system and rolling up a mod would be code WYSIWYG. (With Python, your going to need to get the whitespace correct as a modder, not the most fun thing in the world)
The idea of this mod layer is really 2 pieces:
1) Performance Optimization / Creation: this should be C [whatever], preferably C++ to keep the languages vendor independent. I care about this kind of thing as I am never going to buy a MS dev environment. Visual Studio all you want to, my nakedly generated code just keeps trucking while you are patch dependent. This means people can create new mechanics and improve the engine, while keeping the barriers to entry skill rather than finance based.
2) Modder Scripting: Lua seems a much better option for the general programming audience you want to have access to this functionality. (See arguments above) Since you want people to be able to create interesting quests, stories, scripts, etc use the easier to learn language.
Heavenfall's comparative list of games I think argues this point very well. You CAN create great stuff with Python. MORE people create great stuff, with more differences between what they are creating, in Lua.
P.S. Also anyone who wants to tell me a simple way to deal with Python compiling, PLEASE DO!
Once you know how to code in one language, learning another is like walking in different shoes. A couple of hours stumbling around and then you get your legs. A couple of days and it becomes your new automatic mode, to the degree that you'd have to spend a little time re-wiring yourself when you go back to coding in your preferred language.
I think primary priorities should be performance, ease of integration, and development costs, as all of the languages seemingly on the table have enough of a support base to work for the mod community.
Short version: either Lua or Python is a fine choice.
I've used Python for many years and Lua for about a year (as an embedded language in an objc project). Both are high level, dynamically typed languages. Both are easy to learn, and let you express yourself without much overhead.
I think that Lua has a nicer embedding API. Also its VM is lighter weight.
Python is a language with a much larger collection of libraries (both standard and third party). Python is a richer language with better support for large programs than Lua. Python also has different VMs, so depending on how the game is implemented IronPython might be a better choice than cPython.
Anyway I don't think it matters too much which you choose. But please don't choose C++ or any other low-level, complex, compiled language. This kind of language isn't a good fit for modders.
Also I feel the need to mention to people who are worried about Python's use of white space a block delimiters. It isn't an issue. No one who uses Python has a problem with it. Only people who haven't used Python yet think it's a problem. Python isn't perfect, but this isn't the thing to criticize.
The only scripting language i'm fluent in is nwscript.. which is similar in form to angelscript from what i see(prob cause both are based on C++). Python Is a pain in the rear to deal with imho and i've never touched Lua. Come to think of it.. anything but python is my preference lol
Background Information Part II:
Dynamic Typing (used in Python and Lua) seems like a good idea at first, but it can lead to bugs that are REALLY difficult to find.
C++ and AngelScript have strong typing, which can be a drag at times but is nothing next to the problems of dynamic typing.
Example: in the code snippets I put up earlier, with dynamic typing you can pass text (say "Hello World") as 'n', and it will try to preform math operations on it. The best case scenario is the script will crash. With strong typing, the code will never be built and you will get an error that (if the code that is building it is any good at all) will tell you where you made the error.
------------
Indents are really error prone and may cause 'silent bugs' that are hard to find (like dynamic typing can). And writting "end" is a waste of characters compared to brackets "{}". Also after typing "end" a few thousand times you will come to type it really fast and hit the keys in the wrong order, causing yet more work.
AngelScript supports Object Oriented Programming the same way C++ does, with a touch of Java (explicitly saying if things are private or public). This is better the Lua and the formatting is better than Python's.
-------------
http://www.angelcode.com/angelscript/sdk/docs/manual/index.html
AngelScript provides away to add a JIT (Just In Time) Compiler to transform the bytecode into machine code that will run directly on the processor (longer load time, but the scripts will run faster). The info needed to create one is well documented. Stardock could give a way to specify one to use (a config option to select a DLL that has the code) and allow the community to make one if it is needed.
Lua and Python has more users, but there are a number of programming and scripting langauges similar to AngelScript (from what I have seen, scripts in Neverwinter are similar). In any case, whatever is picked learning the langauge is the easy part of writting scripts to mod games.
It will not happen often (particularly if you use a code editor that automatically does indenting... though then it is still possible), depending where it occurs it can create sutble bugs that will be hard to find.
Compile time errors are usually infinitly better than runtime errors (unless it involves [complex] templates, it which case it is only half as big of a diffrence).
My two cubits and keep in mind a lot of this changes depending on which Python implementation you're working with (I'll assume CPython in this case):
Pros for Lua:
+ Smaller memory footprint than Python. Source: http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=python3&lang2=lua
+ Better support for multithreading. Multiple Lua interpreters can exist in a process and run independently. CPython relies on a global mutex called the global interpreter lock to achieve similar functionality because the Python garbage collector isn't thread safe. There's a performance hit in that regard.
+ Doesn't use reference counting for memory management (although to be fair, Python has a cycle detector to detect and handle circular references. This might be a pro on the Python side for memory management simplicity. In Python, everything is a pointer.).
Pros for Python:
+ Syntax is a little simpler than Lua and there is a plethora of beginner documentation. (So much so that MSU recently switched their intro to programming course over from a C++ based structure to a Python based one, which has apparently has gone over very well with non-CS students).
+ ctype system can access objects in DLLs without writing a C wrapper
+ Has built in rich OO capabilities. Lua doesn't have these out of the box but they can be emulated.
+ Open source Cython library (http://cython.org/) trivializes writing C/C++ extensions for Python code to access.
C++ gets my vote, I understand that wasn't the question but..... well there ya go
I've not used Lua but have limited use of Python.
From what I've read both are going to be relatively simple for modders to use.
Lua seems to be designed to interface directly with C++ so is faster and simpler.
Python has better OO capabilities but Lua can still do simple OO.
Without having used it I'd pick Lua with the ability to bring in C++ modules. That way simple stuff can be done purely in Lua but the complex mods would bring in C++ modules - which I think from a mod project management perspective would be a cleaner model.
There are many great features available to you once you register, including:
Sign in or Create Account