views:

385

answers:

2

I've written a game engine, which i want to integrate scripting into. However, i've looked at the available choices, which seem to be the following:

The problems with those are (respectively):

  • Built for XNA 1 -- there's an XNA 3.1 port but it's under the Apache license which i'm not sure is compatible with our goals (and it has a bit obtuse syntax)
  • Appears to not properly use type-safe objects (e.g. ArrayList over generics)
  • Is in beta, and only runs on XNA 3.0

So, to summarize my specific needs (in order of importance most to least):

  • Needs to run on XNA 3.1
  • Needs to run on the XBox and Windows
  • Should have a relatively simple API -- something closer to Jint's than Xnua's
  • preferably uses Lua, C#, or similar languages
  • Must be commercially sellable -- if some form of credit is needed, then that's fine.

Are there any scripting solutions that meet my needs, or will i have to (eventually) roll my own?

+4  A: 

In my opinion, when you're using C#, why bother with integrating another scripting language?

The only good reason I have come up with is when you have data-driven objects (eg: levels/maps) that you want to "script", with a faster edit-test cycle than you could get by just using Visual Studio as your "script editor".

But just because you can't use Visual Studio, doesn't mean you can't let .NET and the C# compiler do the bulk of the work! To this end, I will direct you to a question I asked here a while ago: Recompile C# while running, without AppDomains

(Plus you can still use Visual Studio, with all its IntelliSense magic, if you set it up right.)

Admittedly this is a "roll your own" solution - but it meets your needs, is relatively easy to implement, and comes with huge advantages.

Andrew Russell
One could say the same when talking about C++, or maybe Java, or... Well, you get the point :) I want to add it for a couple of reasons -- it would make my game more moddable should i choose to do a PC release, and it would also be nice to have a lighter weight language that doesn't involve a whole recompile every testing run.
RCIX
@RCIX this is true - although C# is one of the few languages where it's really easy! The C# compiler is part of the framework - so PC modders wouldn't even need VC# (although Express is free) if you set it up right. As for recompiles - it will just be your "scripts" assembly, not a full build - and if that is too slow (that's a lotta scripts), you could chop it up further. "Weight" is more subjective - and it depends on what kind of API you expose for scripting. For public modding you might also want to look into .NET Code Access Security stuff.
Andrew Russell
A: 

What kind of scripting do you need exactly? What kind of game?

I've always figured XML would be a great scripting language, as it is heiarchy based. And depending on the node in a childlist, you could easily call different functions depending on what you needed.

Granted, this could be extended to fit on needs. But here's an example of RPG dialog in XML, where each tag would open up a new window on the screen to display text.

    <game>
       <dialog>
           <character type="womanA">
                <event type="crops-died">
                  <speech text="The weather has been so horrible.  The crops have died" image="womanAfarmer" />
                  <event type="cow-died">
                     <speech text="I'm so sad my cow died." image="womanAfarmer" />
                     <speech text="Sorry to hear that." image="primaryCharacter" />
                     <exit />
                  </event>                      
                  <exit />
                </event>

                     <speech text="Today is a beautiful day!" image="womanAfarmer" />
                     <speech text="Oh noes!  A killer sandworm!" image="primaryCharacter" />
                     <battle type="bossSandworm" setup="1"/>
                      <exit />
           </character>
       </dialog>
    </game>

I did actually have a prototype of this system working 5 years ago. You parse the XML file and compare what to do with each node, depending on the current variables of the game. How you would react to each node too would influence how the XML is parsed. It wouldn't be hard to come up with decision trees within the XML structure; e.g., did user select YES or NO?

In the example above, for an RPG, if the player talks to a character, you get the character information. If the character type equals womanA, you go down that node path. From there on out, you can check to see if some events have occured to change dialog. If the "crops have died", store that event somewhere in memory (list of strings :P) and see if that list contains "crops-died". If so, go down that node path. Has "cow-died"? If so, go down that node path.

Each path has different dialog, and the node means stop parsing XML and resume regular gameplay. If you notice, talking to the woman with the cows and crops alive means you get to face a sandworm boss :P

In addition, you can compound dialog. If the crops are dead but the cow is alive, the person would just say "The weather is so horrible. The crops are all dead." However, if the cow is dead as well, the character would say "The weather is so horrible. The crops are all dead" in addition to "I'm so sad my cow died." to the player responding "Sorry to hear that", because they're all part of the same chain of events.

Actual mileage per program may vary, and it wouldn't be too hard to switch the embedded dialog within this file with references like, 'stringA' which would be located in another file. That way, you could have multiple files of the text in different languages, and just need to point to the correct file to get the language-specific text :)

Jeffrey Kern