3

Say I want to include a game mechanic where players are invited to code up some algorithm to control robots which would defeat the enemy and protect the tower efficiently. Most games I've seen to implement something like that, support Lua. But what if they accepted a .Net compiled library with implemented in C# (or Java for example) interfaces, essentially doing the same thing? How is it a better or a worse choice?

Code may (not) compile in either case. Some players may (not) be familiar with one of the languages. The computer may not have .Net (or Java) framework installed (but then the game usually comes with at least some redistributable packages, so it may as well include those too). These obvious arguments go either way. Is there some important reason that interpreted languages are the norm, and not compiled which I'm not aware of?

user1306322
  • 1,399
  • 1
  • 19
  • 38

1 Answers1

5

Generally compiled languages are avoided as scripting languages because of the overhead of compiling them. Many of the points in the answers to Why do we use scripts in development? are relevant (even though I agree your question isn't a duplicate).

Primarily the choice comes down to iteration speed: it is (often) way faster to omit the compilation step entirely to achieve quicker turnaround times for testing new features or tweaking existing ones during development. When it comes to then exposing that scripting mechanism to players as a core gameplay feature, why switch to a different language?

The overhead of the interpretation or JIT-compilation or whatever used by the scripting language is usually not sufficient enough to warrant switching out the entire scripting technology stack to one that is pre-compiled when ship time rolls around. Particularly since that new technology stack probably hasn't been battle-tested and stressed during development nearly as much as the "interpreted" option everybody was using up until ship time.

As an extreme over-generalization, languages designed to be compiled offline tend to be heavier-weight and more cumbersome to integrate (and lock down) as scripting languages as well, including when it comes to debugging tools. When that generalization holds, that often contributes against that language in the cost/benefit analysis.

  • 3
    I'd add onto this to say that in games where "players are invited to code," they're usually writing one-off gameplay logic or event handling. The type of thing that runs only a handful of times in any frame - not millions of times like particle systems or rendering or physics simulations. So, even if it's executed with less-than-optimal efficiency, it's rarely the determining factor in game performance. Time spent making user scripts compile to native code might be more productively spent tuning core game & engine systems instead, for more performance payoff. – DMGregory Sep 26 '16 at 20:23
  • Yes, good point. –  Sep 26 '16 at 20:24