c# as a scripting language?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • c# as a scripting language?

      Hello all, and thanks to the authors for what's quickly become my favorite book on game development.

      I'm a c# developer who's only recently taken the dive into game development. I was originally looking at XNA, but became spooked by the fact they seem to have abandoned it. Looking for alternatives, I decided to go the directX route, and found this book. Learning a lot so far, but I still have a long way to go, so forgive me if this seems a naive question.

      I understand the benefits of using a scripting engine, but I wonder is there any reason not to use c#? I use it every day for work, so I'm able to get along quite quickly in it and on the surface at least, it seems to provide all the features one would expect or need from a scripting language.

      I'm really just hoping someone knowledgable in the topic would take a moment to give me some thoughts, both for and against.

      Cheers,
      Fearsidhe
    • You should check out Unity, they use C# for scripting as well as javascript(unityscript) and python(boo), I image that implementing C# is not quite as simple as Lua or Python, especially since in Lua's case it was actually designed from the ground up to be used in native code, it is definitely possible.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • C# is more verbose than Lua or JavaScript.
      In Unity scripts written in C# 2 times bigger than in JavaScript. I don't think the strong typing of variables in C# or OOP features will be "killer feature" in case of scripting.

      The post was edited 1 time, last by andjey ().

    • To be honest, there are no particular features that make me want to use c#, except for the fact that it's already integrated into visual studio with intellisense, and it should be relatively simple to get unmanaged c++ to play nice with c#. That, and I've already years of experience programming in c#.
    • I think in the case of Unity, it was the best way to expose lower level code to the programmer, since you don't get access to the actual source code.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

    • I'm really just hoping someone knowledgable in the topic would take a moment to give me some thoughts, both for and against.


      Well, I don't consider myself to be knowledgeable in scripting, but surely Rez is, so here's a reply from rez about a related topic:




      In the professional game development world, you typically use C++ for the engine and some higher level language (Lua, Python, C#) for the gameplay code. Most of our gameplay programmers write very little C++ on The Sims 4. Indie games are all over the place. STL was written 100% in C++. I think Super Meat Boy was all C#. I know Monaco was like 95% C# with a few bits of C++ (like line-of-sight).



      I think that reply speaks for itself.



      I understand the benefits of using a scripting engine, but I wonder is there any reason not to use c#? I use it every day for work, so I'm able to get along quite quickly in it and on the surface at least, it seems to provide all the features one would expect or need from a scripting language.


      One advantage of using C# (IMHO) is that you don't have to handle memory stuff and that it is more high-level than C++.
      In my opinion, it is easier to code more complex systems in C# than in C++ (one reason for this, is of course, that you don't even need to think about memory leaks, even though one should become more used to that with experience).
      If you've worked so long with C#, I should be much easier for you to build scripts in C# than in Lua or something else. (Though, of course, as has already been stated, Lua is designed to be used as a scripting language and has only very little syntax and has ways to express more complex things in a very elegant way.)
    • I think you'll just find that C# is a heavier weight scripting language than Lua. Pros and cons to each, depending on what you want. Personally I think strongly typed is a huge selling factor, which is why I found C# nice to work with in Unity. That being said, I don't yet have any professional Lua experience. On the title I'm on right now, game play logic is done in C++ and some proprietary data-driven stuff in the engine. No shortage of different solutions to the same sorts of problems :)

      James

      The post was edited 1 time, last by rickvanprim ().

    • I agree with James. Strongly-typed languages may not seem like that big of a deal when you only have a few thousand lines of code, but when you're trying to refactor 10,000+ lines of code in a tangled system, you will sell your soul for strong typing. We use Python on The Sims 4 for our scripting language and I absolutely hate it. Refactoring is nearly impossible to do without introducing a number of bugs. Something as simple as renaming a variable can cause a lot of fallout if you're not careful.

      The pros of Lua are that it's one of the fastest and smallest integrated scripting languages out there. If your goal is speed and size, Lua is a great language. It's also really easy to extend, makes for a great data format (all my data is in Lua tables rather than XML), is easy to embed in a game engine, and is incredibly simple to use. That's why I use it in my personal engine.

      C# is generally harder to use. You end up writing about twice as much code to do what Lua can usually do in half the time. It's much more bloated than Lua and is slower in many cases. Integrating it with C++ is a pain. It's also tied to Microsoft platforms unless you use Mono, which has its own baggage.

      It really depends on your goal. If you like C# and want to use it, go for it. If you want to be a professional game developer, you'll have to learn C++ at some point. But if you just want to play around, go for it. The architecture taught in Game Coding Complete is easily translatable to C#.


      One advantage of using C# (IMHO) is that you don't have to handle memory stuff and that it is more high-level than C++.
      In my opinion, it is easier to code more complex systems in C# than in C++ (one reason for this, is of course, that you don't even need to think about memory leaks, even though one should become more used to that with experience).

      This is mostly correct. 99% of the time, you don't have to worry about memory. The other 1%, it's a real pain. This is especially true in games that use C# as a scripting language. I spent at least a month at the end of The Sims Medieval tracking down memory leaks in C#. Often times those were issues where the link between the C++ and C# objects were broken and the C# object never went away. It can be a real headache. Trust me, there are many times when managing your own memory is actually the easier way to go. I rarely have memory issues in my game engine because I have very explicit object ownership, so things don't get lost nor do I have dangling pointers.

      -Rez