-1

Basicly, I want to create code that I can compile from a STRING that I will be loading from a file. Is that even possible? I did my research and I couldn't find any answers.

Monset
  • 648
  • 5
  • 25
  • can you elaborate a little bit more on what you main goal is and what you are truly trying to achieve – MethodMan Jan 15 '15 at 22:33
  • You may want you search for `System.CodeDom.Compiler` – EZI Jan 15 '15 at 22:37
  • I am making a fighting game and there are classes: Player, Character, Move. So, a character will have some moves and those moves will be checked in Player class. In that idea, some characters will have moves that will include some jumping, dashing, hitting, moving, and all that in different speeds in different times. So I thought, why not code my every characters move? My game code would be too long to write for every single character, so I want to put all that "move" code in files and load them when needed. – Monset Jan 16 '15 at 12:18

1 Answers1

0

Reading your follow-up comment, it sounds like what you would be looking for would be a scripting language rather than compiling C# code dynamically. A scripting language allows you to pass in and execute code as a string, while also allowing to tie in your current execution to that code. For instance, you can pass in the character's current health to the scripting language, and then read back the character's current state (dead? immune? etc). The two most popular languages to do scripting for games are Lua and Python. Both of these languages have .NET libraries/bindings to allow them to be used within C#.

It has been a bit of time since I have set up my own project in C# with Lua, but I believe this tutorial looks very similar to what I was using, and therefore how I answered my question (ie, being able to closely bind them). However, searching Google for "lua C# binding" or "python .NET binding" will give you lots of libraries and tutorials. Which one you ultimately decide upon really comes down to which of those two languages (though there are bound to be many other scripting languages out there as well) you feel more comfortable with using.

I suppose, as EZI said above, it would be possible to compile C# code dynamically. But from your question, it sounds like you'd be looking for a scripting language instead.

Alec Deitloff
  • 447
  • 4
  • 12
  • Thank you for the refference and advice. I think this is what I was looking for. I shall see trough this tutorial and I think, from this, beginner, poin of view, that this willl come in handy in my project. thank you Alec :) – Monset Jan 17 '15 at 13:59