views:

377

answers:

7

The ingame script will control NPC/AI logic.

If I were to implement ingame scripting feature which language should it support?

Keep in mind my implementation will run on multiple platforms like .net, flash, javascript and java.

What are the pro's and con's of the listed possibilities? How long will it take to implement the interpreter?

What features are ingame scripters looking for? What are other games implementing?

I am thinking to vote for javascript due to the fact that everybody can read and write it.

What are your thoughts?

+3  A: 

I would prefer Python for its bindings in many languages.

Cem Kalyoncu
A: 

I think you mean "integrate" the interpreter, and not "implement" it. Depending on your skills, creating an interpreter for a scripting language could take a lot of time.

Geo
This would make more sense as a comment, not as an answer.
+4  A: 

I'd use Lua, because it's terribly easy to embed. Embedding Python appeared to be complicated and I haven't really pursued that.

This link may be of further use if you want to know more about embedding Lua and its advantages/disadvantages.

Michael Foukarakis
A: 

I know for sure that Python and Lua have bindings for .NET and Java -- you can embed the interpreters. Don't know whether there are any bindings for Javascript and Flash.

The problem with Python is that there are three variants all made by different people.

  • IronPython for .NET
  • Jython for Java
  • and the regular CPython

I haven't worked on Jython so I won't comment about it. But there are certain portability issues between IronPython and CPython. For example: IronPython doesn't support native C extensions. If there are scripts written in CPython which use these, you will have a hard time porting them to IronPython. Also, if the IronPython scripts use any .NET libraries, you will have a hard time porting them to CPython.

Implementations of Lua, on the other hand, come from a single place and I don't expect such problems.

Rohit
I don't see why more than one available language implementation would count as a disadvantage. Or why you would use native C extensions in an ingame script.
nikie
I didn't say that having more than one language implementation is a disadvantage, but the fact that they are maintained by different people.
Rohit
A: 

That depends on how complex your code will be (how complicated the behavior of NPCs can become). Tcl, Lua and JavaScript are for simple tasks. Writing large pieces of code in these languages quickly tends to become unmaintainable (especially for casual users).

Squirrel uses a C-like syntax which most people will be comfortable with but how about tooling support? If you have to write everything with Notepad, that will severely limit you, too.

Python is a mature language that is easy to learn (just compare the Lua "tutorial" to the one which comes with Python). While the various Python versions might seem intimidating (see Rohit's answer), the Python code in your game will be the same for all of them. It comes with an IDE (IDLE) and there are other IDEs which support Python which gives you code completion, debugging, running test cases, etc.

Aaron Digulla
Perhaps my opinion is biased, but, in my experience, Lua is easier to learn or teach. It is just that Python has larger community. Don't know what do you mean by 'Lua "tutorial", but Programming in Lua is one of the best CS books I've ever read (http://www.lua.org/pil/).
Alexander Gladysh
Also Lua is much easier to embed. Lua was designed as embeddable language from the grounds up, but Python was not.
Alexander Gladysh
As for "Lua is for simple tasks". We have 160 KLOC+ of Lua code in our project. My personal opinion: Lua is quite maintainable.
Alexander Gladysh
How big is the "recognize what your code does when returning after a month" factor of the code for a casual user? As for the "Lua tutorial", I'm referring to the online documentation. It expects users to understand EBNF, so -1 in my book.
Aaron Digulla
Also, I can't see support for complex structures like lists, maps, sets, objects, classes. I like my languages to come with a big quiver full of arrows so I can solve my problems efficiently without having to write a linked-list module first.
Aaron Digulla
On complex structures support: Lua tables are all what you've mentioned. And they are quite good for it. If you need "convenience wrappers" to feel safe, well, there are libraries. Take LOOP for example: http://loop.luaforge.net/
Alexander Gladysh
On "recognize what your code does when returning after a month" factor: the same as it is for any conventional language. With added bonus of very sane syntax which would not let you spoil this factor as you could in, say, Perl.
Alexander Gladysh
On online documentation and EBNF. You seem to refer to Lua Reference Manual: http://www.lua.org/manual/5.1/. It is an official document about what Lua is. It is not a tutorial, it is almost a standard of the language. It is supposed to have some EBNF inside. If you need introductory docs, there are plenty. Take abovementioned excellent PiL for example.
Alexander Gladysh
+4  A: 

Use Lua. It is a beautiful language, widely adopted in game industry.

There are Lua bindings for most of your platforms:

There is also llvm-lua project, which may be helpful for porting Lua to other platforms.

As for JavaScript as a host platform... This subject recurrently appears in the Lua mailing list, but no serious solution were published yet. If you really need to host Lua in JS, please ask in the Lua mailing list, perhaps some people could share their experience on the subject.

Alexander Gladysh
A: 

If you want to use Python consider using Stackless as it is rather better at threading than stock CPython. It's used in some MMORPGs (EVE Online, IIRC) so it's got some track record in games. Plus, it is very good for continuations (part of the reason it was developed in the first place), which is quite a good model for 'simulation' type logic that one use in games.

ConcernedOfTunbridgeWells