views:

1818

answers:

10

So I've been running into a debate at work about what the proper role of a scripting language is in game development. As far as I can tell there are two schools of thought on this:

1) The scripting language is powerful and full featured. Large portions of game code are written in the language and code is only moved into C++ when performance dictates that it's necessary. This is usually something like Lua or Unrealscript.

2) This scripting language is extremely limited. Almost all game code is in C++ and the language is only there to expose the underlying functionality to designers.

My frustration comes from seeing approach number two frequently abused, with large systems implemented in a language that does not have the features that make that code maintainable.

So I started out supporting approach number one, but after talking to some designers I realized that many of them seem to prefer number two, and its mostly programmers who prefer one.

So I'm still left wondering which approach is better. Am I just seeing bad code and blaming the tool instead of the programmer, or do we need really need a more complex tool?

+4  A: 

I can't really see the argument that large amounts of scripted code is going to be superior to large amounts of C++. One could make the counter argument. I've seen terrible large projects written in scripting languages that started out with the scripting mentality--getting things done quick and dirty. This unfortunately doesn't scale well. There's really no way to make a code quality argument based solely on the programming language. People can write gobs of maintainable code in any language, compiled or scripted.

Anyway, its really impossible to know the line between your "approach 1" and "approach 2" without knowing where the performance bottlenecks are and what your users are going to most want to "script".

I would suggest an "approach 3" which is to do it all or in part in C++ and expose a clean SDK in C++. This would have the advantage of forcing you to write your code as if it were a user interface someone outside your organization has to use. It would hopefully cause it to be more maintainable AND have the added side effect of implementing your scripting interface for you. All your scripting interface would need to do now is forward to your SDK. Viola!

With this approach you avoid having to draw a line between the realm of what is "scripted" vs what is in C++. You and your users keep a choice to either add functionality in C++ with the SDK or use a scripting language.

Doug T.
+3  A: 

As usual, I think the answer is "it depends."

There's NO WAY Halo 3 or Call of Duty 4 could have been based primarily on scripting. Top-rated AAA titles must, by definiton, push the envelope of any platform they touch. This just can't be done with scripting.

Casual games, however, are a different story. Major game eninges like Unity have lots of scripting built in.

There is also a market for mods. A solid game engine with a good scripting environment can be a platform for tweaks, derivations, and in some cases altogether new games. Counter Strike is my personal favorite example. I think you're limited in this case to FPS run-and-gun type games.

So, there is a place for scripting in games but it will probably stay in the small/casual game and modder's space.

Dave Swersky
Scripting doesn't have to be inherently slow. UnrealScript iirc gets compiled into bytecode which gets executed. And if that's too slow you could still JIT. Scripting provides a domain-specific language which may work better for many parts of the game code (iirc, UT99's game modes were scripted).
Joey
It's nigh certain that Halo 3 and Call of Duty 4 use scripting for all meaningful interactions with the player. Sure, the graphics control, sound control, mapping system and whatnot are all in C++, but the things that make it a game (as opposed to a technical demo) are scripts.
Tim Sullivan
Dave Swersky
That is a complete guess though, isn't it. I'd potentially agree with that figure, but the point is that about 90% of that C++ is the code that's been fixed and unchanging, except for bug-fixes, all the way from Halo to Halo 3. Which is, of course, another guess.
deworde
Also, as far as "Run and Gun", are you seriously suggesting that when there's no value in scripting in an RTS or MMORPG? In the area of class capabilities for example? REALLY?
deworde
Anybody have more details on Halo's scripting engine? There's a brief mention on Halo "supporting a robust scripting engine" here: http://www.gamasutra.com/view/feature/3489/producing_audio_for_halo.php
Ken Fox
+8  A: 

I think the balance you want is something to this effect: you want game logic in script, but game functionality in code.

One big big advantage of script is that you can set up waits easily. For instance:

enemy = GetObjectFromScene ("enemy01"); in 5 seconds { enemy.ThrowGrenadeAt (player); }

Just a contrived example. That kind of logic would be annoying to setup in C++. Script can make it easier to express this kind of logic, but you'd want the actual functionality (the functions it calls) to be in C++.

And script doesn't have to be slow. There are heavily scripted games running at 60fps on consoles, but it requires a good design and finding the right balance between your options 1 and 2 above.

Dan Olson
The script is still usually slow. The game just doesn't spend much time running script.
BigSandwich
A: 

The game development community already uses scripting as a very common way of building user interfaces and tuning AI responses. You can find lots of info on sites like Gamasutra. The interesting thing is that standard languages are starting to replace custom interpreters.

Two of the best scripting examples in AAA games that come to mind are World of Warcraft (uses Lua) and EvE Online (uses Python). EvE uses scripting on the server-side too: they have a significant investment in Stackless Python.

Update: Performance will essentially be a non-issue due to multicores. Even low end machines will end up with more cores than the display and model updates need. You might as well spend one of those cores running a scripting solution for the UI.

Ken Fox
Performance will never be a non-issue because each game will always be competing with every other on scene density, realism, character detail, etc. I've heard "perf isn't our issue any more" so many times from so many devs, and they've always been wrong, sometimes company-destroyingly so.
Crashworks
Games already use several cores - often using 2, 3, or more cores. (The graphics card has quite substantial processing power these days).No, the issue is the bandwidth required - however that's a moot point with the OP's question.
Arafangion
Large numbers of cores are coming -- more than I expect will be used for rendering, physics, etc. because parallel algorithms are very difficult to write and don't always scale with the numbers of core. It makes sense to put a scripting engine on a core to increase development speed.
Ken Fox
+9  A: 

I think designers need to see a language suitable for their domain. That's not negotiable: they have to spend their time designing, not programming.

If scripting allows fast development of product-worthy game code, then the programmers should be doing it too. But it has to be product-worthy: doing everything twice doesn't save time. So you have to keep scripting in its place. If a developer can script the inventory system in a week, or write it in C++ in a month, then you want full-featured scripting, if only to give you more time to hand-optimise the parts that might conceivably hit performance limits. So not the inventory, or the high-score table, or the key-mapping system, or high-level game logic like what the characters are supposed to be doing. That can all be scripted if doing so saves you any time at all to spend on speeding up the graphics and the physics: programmers need to be able to work out exactly what the bottlenecks are, and senior programmers can make a reasonable estimate of what isn't.

Designers probably shouldn't know or care whether the programmers are using the scripting language to implement game code. They shouldn't have an opinion whether (1) is good or bad. So even if the programmers are right to want (1), why is this inconveniencing the designers? How have they even noticed that the scripting language is full-featured, if all they ever need is a fairly small number of standard recipes? Something has gone wrong, but I don't think it's that Lua is too good a language.

One possibility is that using the same scripting language for both, becomes an obstacle to drawing a sharp line between the interfaces used by designers, and the interfaces internal to the game code. That, as I said at the top, is not negotiable. Even if they're using the same scripting language, programmers still have to provide the designers with the functionality that they need to do their job. Just because designers use Lua to code up AI strategies and conversation trees, and Lua is full-featured language capable of writing a physics engine, doesn't mean your designers are expected to write their own physics engine. Or use more than 10% of Lua's capabilities.

You can probably do both (1) and (2), mind. There's no reason you can't give the programmers Lua, and the designers some miniature under-featured DSL which is "compiled" into Lua with a Lua script.

Steve Jessop
+10  A: 

The compile-link-run-test cycle for compiled C++ code when you're dealing with something as complex as a video game is very, very slow. Using a scripting engine allows you to make large functional changes to the game without having to compile the program. This is a massive, massive time savings. As you say, things that need optimization can be moved into C++ as required.

AAA engines are highly driven by scripting. Torque, used for Tribes II (and many other games!) is scripted, Unreal has Unrealscript and so on. Scripting isn't just for mods, it's key to efficient development.

Tim Sullivan
In practice, I'm not sure its as onerous as you are stating. The whole system isn't recompiled every time you make one change. Plus with precompiled headers you can mitigate compile times *a lot*. Still you are correct in that its something you have to factor in.
Doug T.
Yes, my experience thus far has been that waiting for scripts to compile hasn't been much faster than waiting for code to compile.
BigSandwich
A: 

As has been said before; use scripting for game logic, and C++ for game functionality. An example would be scripting a game mode, but using C++ for rendering.

TraumaPony
+2  A: 

One of the best examples of scripting in action is Civilisation IV. It uses Boost Python. As a result, it is horribly slow. A clear counterpoint to the statement that "code is moved into C++ when performance dictates that it's necessary".

The proper way is to design an architecture up fron, and decide which problems are computationally hard and which are complex to specify up front. Graphics, physics, pathfinding, instant feedback on input, text to speech - all clearly computationally hard. "Friendly or hostile stance", "defend or attack", "spend or save" type AI decisions are all complex to specify up front.

The conclusion is that you want to expose capable, but soulless actors to your scripting code. The scripting code describes what the actors should do, but the C++ code takes care of the how.

With regard to the compile-link cycle, it's important to have a proper modular architecture. When you are working on the pathfinding logic, you should never have to compile graphics code. Also, tools like Incredibuild can help speed up compile times. Big game firms probably already have a render farm, which can double up quite well as a compile farm.

MSalters
I'd agree with your general point, but I'm pretty sure that someone'll point to some games programmed in C++ which are also horribly slow. "The right programmer can write COBOL in any language."
deworde
A: 

If we split a game into two parts: The engine and the actual game (design).

A solid top class game engine is most likely written in C/C++ and some people even optimize further with assembler code. You can do a lot of neat really fast stuff for graphics and physics with specific CPU instructions. There is no way to get performance when rendering large landscapes or multiple complex objects from a scripting language only.

When it comes to the game itself where are a lots of aspects that can be done in slower but higher level programming languages. AI and other game logic can be written in script with success. It can speed up development and it opens up for modding and community expansions in a simple way.

Thanks for responding, but you've completely missed the point. I want to know where to draw the scripting 'line'. I know what scripting languages are used for and how most game engines are put together.
BigSandwich
I’m sorry. I’m completely alien to the approach of this development concept, writing code twice, first a semi-programmer in one language and then with a programmer in a different language. If a designer is skilled enough to write Lua he/she is skilled enough to write a skeleton code in C.
You mean approach number 1? The point is rapid prototyping of ideas. C or C++ isn't very good for that, and that's really what the designers want (ie to Design). Coding and performance are not their objectives.
BigSandwich
+1  A: 

So I started out supporting approach number one, but after talking to some designers I realized that many of them seem to prefer number two, and its mostly programmers who prefer one.

This should make obvious sense: if the scripting language is "powerful and full featured", there is an onus on the designers to have to create the systems, since this opportunity is available to them. On the other hand, if the scripting language only exposes small details of the hard-coded game, then the programmers have to create those systems, since designers cannot. I'm not saying each side is lazy, but obviously both have individual skills the project requires them to focus on (since nobody else can do them as effectively), meaning there is always an interest in getting someone else to do a given task if possible.

And following naturally on from this, the proper role will depend on how the human resources in your company are laid out, in conjunction with any performance requirements of your game. Once you have an idea of how many people will need any sort of scripting, you'll know how much of the game will require it, and therefore can decide how how wide or narrow the interface needs to be. This contributes to what the 'domain' of the language would be, as mentioned by onebyone.livejournal.com above.

(For what little it's worth, I'm a professional game developer and also the moderator of the Scripting Languages forum on Gamedev.net.)

Kylotan