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?

  • 2
    \$\begingroup\$ Possible duplicate of Why do we use scripts in development? \$\endgroup\$
    – Tyyppi_77
    Sep 26 '16 at 15:42
  • \$\begingroup\$ That talks about development, I'm talking about the things you do while already playing the release version. \$\endgroup\$ Sep 26 '16 at 15:43
  • \$\begingroup\$ I understand that, however I feel like some, if not most, reasons are the same in both. \$\endgroup\$
    – Tyyppi_77
    Sep 26 '16 at 15:45
  • 1
    \$\begingroup\$ I don't think so. There's no need to "recompile the whole game" in either case, the engine is designed to be decoupled from the user's implementations, either by exposed interfaces, or variables. In both cases coding happens while you're playing the game, so "run-time" essentially, save for negligible compilation time. \$\endgroup\$ Sep 26 '16 at 15:47
  • 1
    \$\begingroup\$ Otherwise I'd be at risk of not showing prior effort. It's a double-edged sword and this edge seemed less sharp. \$\endgroup\$ Sep 26 '16 at 16:35

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
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Sep 26 '16 at 20:23
  • \$\begingroup\$ Yes, good point. \$\endgroup\$
    – user1430
    Sep 26 '16 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.