2

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?

zproxy
  • 3,509
  • 3
  • 39
  • 45
  • Embedding Javascript is orders of magnitude more complex than embedding Python or Lua (well, at least before V8 I don't know how it is with it) – Vinko Vrsalovic Sep 16 '09 at 07:54
  • @Vinko Vrsalovic: JavaScriptCore (the JS engine in WebKit) has had a standard stable C API (and ABI) for around 3 or 4 years (it's a system framework on MacOS even) – olliej Sep 16 '09 at 08:20
  • See this similar question: http://stackoverflow.com/questions/1406836/ – Colin Macleod Sep 16 '09 at 08:20
  • V8 is easy, at least building the library and running simple JavaScript from a C application is easy. JIT only though, ARM and X86 backends. If you want to target X360 or PS3 there's no PPC support. I'm confused by OP's platforms, generally multiplatform means "written in C and compiled for PC, XBOX, etc. using platform specific code where necessary." Sounds like you will be targeting multiple programming languages, which significantly complicates things. What exactly do you mean? What is your implementation language? Are you writing a library in C and providing bindings for other languages? – Whatever Sep 16 '09 at 08:26

7 Answers7

5

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
  • 39,737
  • 6
  • 87
  • 123
5

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
  • 39,865
  • 32
  • 103
  • 160
3

I would prefer Python for its bindings in many languages.

Cem Kalyoncu
  • 14,120
  • 4
  • 40
  • 62
0

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
  • 93,257
  • 117
  • 344
  • 520
0

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
  • 7,449
  • 9
  • 45
  • 55
  • 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. – Niki Sep 16 '09 at 08:10
  • 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 Sep 16 '09 at 08:48
0

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.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    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 Sep 16 '09 at 08:36
  • Also Lua is much easier to embed. Lua was designed as embeddable language from the grounds up, but Python was not. – Alexander Gladysh Sep 16 '09 at 08:37
  • 2
    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 Sep 16 '09 at 08:40
  • 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 Sep 16 '09 at 10:25
  • 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 Sep 16 '09 at 10:30
  • 1
    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 Sep 16 '09 at 20:44
  • 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 Sep 16 '09 at 20:47
  • 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 Sep 16 '09 at 20:49
0

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
  • 64,444
  • 15
  • 143
  • 197