Including scripting capability to.NET applications

I have a plot created in C#. It makes use of a database as back-end. It's. a trading card game, and also I intended to implement the function of the cards as a manuscript.

What I suggest is that I basically have a user interface, ICard, which a card class applies (public class Card056: ICard) and also which has function that is called by the video game.

Currently, to make things maintainable/moddable, I would love to have the class for each and every card as resource code in the database and also basically compile it on first usage. So when I need to add/change a card, I'll simply add it to the database and also inform my application to rejuvenate, without requiring any kind of setting up release (specifically given that we would certainly be speaking about 1 setting up per card which suggests thousands of settings up).

Is that feasible? Register a class from a resource documents and afterwards instantiate it, and so on

ICard Cards[current] = new MyGame.CardLibrary.Card056();
Cards[current].OnEnterPlay(ref currentGameState);

The language is C# yet added incentive if it's feasible to write the manuscript in any.NET language.

2019-05-03 17:52:40
Source Share
Answers: 6

The major application that my department markets does something really comparable to give customer customisations (which suggests that I can not upload any kind of resource). We have a C# application that lots vibrant VB.NET manuscripts (although any.NET language can be conveniently sustained - VB was picked due to the fact that the customisation group originated from an ASP history).

Using.NET is CodeDom we compile the manuscripts from the data source, making use of the VB CodeDomProvider (aggravatingly it defaults to.NET 2, if you intend to sustain 3.5 attributes you require to pass a thesaurus with "CompilerVersion" = "v3.5" to its erector). Make use of the CodeDomProvider.CompileAssemblyFromSource method to compile it (you can pass setups to compel it to compile in memory just.

This would certainly cause thousands of settings up in memory, yet you can place all the vibrant courses' code with each other right into a solitary setting up, and also recompile the entire great deal when any kind of adjustment. This has the benefit that you can add a flag to compile on disk with a PDB for when you are examining, permitting you to debug via the vibrant code.

2019-05-19 21:31:18

If you do not intend to make use of the DLR you can use Boo (which has an interpreter) or you can take into consideration the Script.NET (S#) project on CodePlex. With the Boo remedy you can pick in between assembled manuscripts or making use of the interpreter, and also Boo makes a wonderful scripting language, has an adaptable syntax and also an extensible language using its open compiler style. Script.NET looks wonderful also, however, and also you can conveniently expand that language along with its an open resource task and also makes use of a really pleasant Compiler Generator (

2019-05-10 05:33:33

You can make use of any one of the DLR languages, which give a means to actually conveniently organize your very own scripting system. Nonetheless, you do not need to make use of a scripting language for this. You can make use of C# and also compile it with the C# code carrier. As long as you load it in its very own AppDomain, you can load and also unload it to your heart's web content.

2019-05-07 18:17:39

Oleg Shilo's C# Script solution (at The Code Project ) actually is a wonderful intro to giving manuscript capacities in your application.

A various strategy would certainly be to take into consideration a language that is especially constructed for scripting, such as IronRuby, IronPython, or Lua.

IronPython and also IronRuby are both readily available today.

For an overview to installing IronPython read How to embed IronPython script support in your existing app in 10 easy steps.

Lua is a scripting language generally made use of in video games. There is a Lua compiler for.NET, readily available from CodePlex--

That codebase is a wonderful read if you intend to learn more about constructing a compiler in.NET.

A various angle completely is to attempt PowerShell. There are countless instances of installing PowerShell right into an application-- below's a detailed task on the subject : Powershell Tunnel

2019-05-07 17:29:36

Yes, I thought of that, yet I quickly identified that an additional Domain-Specific-Language (DSL ) would certainly be a little bit way too much.

Basically, they require to connect with my gamestate in perhaps uncertain means. As an example, a card can have a regulation "When this cards enter play, all your undead minions obtain +3 strike versus flying adversaries, other than when the adversary is honored". As trading card video games are turn based, the GameState Manager will certainly discharge OnStageX occasions and also allow the cards change various other cards or the GameState any way the card requires.

If I attempt to create a DSL, I need to implement an instead huge attribute set and also perhaps frequently upgrade it, which changes the upkeep job to an additional component without in fact eliminating it.

That's why I intended to remain with a "actual". NET language to basically have the ability to simply discharge the occasion and also allow the card adjust the gamestate any way (within the restrictions of the code accessibility protection ).

2019-05-07 17:29:12

You could be able to make use of IronRuby for that.

Or else I would certainly recommend you have a directory site where you position precompiled settings up. After that you can have a reference in the DB to the setting up and also class, and also make use of representation to load the correct settings up at runtime.

If you actually intend to compile at run-time you can make use of the CodeDOM, after that you can make use of representation to load the vibrant setting up. Microsoft documentation article which might help.

2019-05-07 16:34:48