开发者

Scripting in C# - Portable Library for XNA and 360?

I'm just wondering if this is even possible; how to do non-complicated scripting within C#. Basically, let's say I have a structure as such:

Structure
   int a
   int b
   int c

   Function ParseValue(pString as String)

         try
              return interpret(pString)
         catch
             return 0
         end try

   End Function

ParseValue would be where my question lies, specifically 'interpret'. 'Interpret' is just a generic placeholder for what code/implementation that I'm looking for.

Let's say I pass in a value for pString as 'a + b + c'. So, the code would the interpret the string as "return the value of adding a + b + c" together. And If I cannot do that, "return 0". A good example of having to return 0 would be "(a + b) / c", and the value of c = 0 (cannot divide by zero).

Is it possible to do this? I know A LONG time ago Iwas able to use the Microsoft Scripting Control to achieve similar functionality in VB6, but yah. That's 12 years ago, and not C#/XNA/360 compatible. I think :P

EDIT: The language that can be in开发者_StackOverflow中文版terpreted doesn't matter. If I can use VB.Net or C# and interpret VBSCript or JScript in it, I'm happy with that.


This is the very first interesting usage of Mono's CSharp compiler to achieve some scripting features,

http://gent.softcatala.org/jmas/bloc/pivot/entry.php?id=449&w=jordis_english_bloc

You can see if the trick can be used on XNA.


I'm not aware of a specific scripting library available for the .Net Compact Framework (ie: one that would work on the 360). You may be able to find one, I just haven't looked. I've seen a Lua interpreter written in C#, but I'm not sure if it works with the Compact Framework. (And I don't remember where I found it in the first place.)

However, you can load pre-compiled assemblies dynamically on the 360 (on Windows you can also dynamically compile them, but the 360 is only able to load them), which would allow you to use any .Net language as your 'scripting' language. The problem, then, is what exactly do you gain by having a scripting language? You could alter scripts without restarting the game, but you still have to go through the compile process, and the debugging becomes much more difficult.

Considering C#'s fast compile speed, I think you're probably better off without a scripting language for your game.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜