Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Game Scripting With Python 186

P. Staurou writes "There is very interesting article about game scripting with Python over at Sylphis3d.com. It talks about how game engines should be structured as operating systems with actors being the processes. The proposed design is based on a special version of Python called Stackless and already successfully implemented in their own Sylphis3D game engine."
This discussion has been archived. No new comments can be posted.

Game Scripting With Python

Comments Filter:
  • EVE Online (Score:5, Informative)

    by Dr_Barnowl ( 709838 ) on Saturday September 17, 2005 @08:20PM (#13587340)
    ... is already using stackless Python, so it's a proven, successful multiplayer online game platform. EVE has upwards of 10,000 players most of the time.
  • by SnprBoB86 ( 576143 ) on Saturday September 17, 2005 @08:27PM (#13587366) Homepage
    This article presents the idea relatively well, but this is NOT A NEW IDEA.

    I'm not sure if Epic invented it, but I can certainly tell you that microthreading, latent functions (such as the sleep in the door example, or a playanimation method that takes game time to complete), and this general idea has been around since at least the original Unreal Engine in UnrealScript (which is now a rather mature scripting language).
  • A quibble (Score:1, Informative)

    by Anonymous Coward on Saturday September 17, 2005 @08:35PM (#13587390)
    The author uses examples with 'try' 'except'. Handled wrong, that makes debugging a LOT more difficult because if your error is in the 'try', you won't get an informative error message. The author has 'except' printing 'oops'. In anything but the most trivial program, you have to be a tad more informative about what's causing the error.
  • Lua, Books (Score:5, Informative)

    by Noksagt ( 69097 ) on Saturday September 17, 2005 @08:37PM (#13587396) Homepage
    It didn't make the front page, but the recent article [slashdot.org] on extending games with Lua is also worth a read. My personal preference is still for Python (I love all of the libraries that it has), but Lua is good if you need some small scripting engine.

    In that article, I was asked about this book [amazon.com], which covers Lua, Python, and Ruby for games. Despite having all of the "right languages," the book is awful. For people wanting to extend games with python, I suggest Game Programming with Python [amazon.com]. This book is a wonderful overview.
  • Not new (Score:2, Informative)

    by Anonymous Coward on Saturday September 17, 2005 @08:41PM (#13587408)
    EA/Dice currently use Python scripts in the latest Battlefield 2 game. You will actually find quite a few games that currently use python already. I dont know why it should be news when game developers already do so and have for a while now.
  • by nicholasfrancis ( 915635 ) on Saturday September 17, 2005 @08:42PM (#13587417)
    As for the language, we used Python in Unity http://www.otee.dk/ [www.otee.dk] for the initial preproduction of GooBall. It was soooo slow. After that we switched to Mono. CPU usage in the scripting logic went for >40% to app. 5%... If you like the Python syntax, you can always include boo http://boo.codehaus.org/ [codehaus.org] which mimics Python very closely, but uses type inference to get type safety automatically. On another note: the article states that Unreal does not use microthreads. That is not correct.
  • by Coryoth ( 254751 ) on Saturday September 17, 2005 @08:52PM (#13587448) Homepage Journal
    The point of using Stackless Python [stackless.com] (as opposed to ordinary Python) is that it provides a particularly good system for handling multiple threads and communcation for threads via tasklets [stackless.com] and channels [stackless.com]. If your game engine works by creating actors as threads then using a scripting language that has a simple to use, efficient, and platform independent threading model is likely of great importance, and Stackless Python offers that.

    If you're generally interested in better threading models, and being able to think and reason about threads and their interactions more easily then you really ought to check out CSP [usingcsp.com]. Multithreading is actually easy if you do it right - it's just that most languages don't.

    Jedidiah.
  • by cduffy ( 652 ) <charles+slashdot@dyfis.net> on Saturday September 17, 2005 @09:13PM (#13587495)
    Stackless is a completely different implementation from CPython, and has extremely different performance characteristics.

    Consequently, your experiences with CPython simply don't apply here -- Stackless is largely focused around doing this kind of thing (microthreads and such) extremely well.
  • by Osty ( 16825 ) on Saturday September 17, 2005 @09:18PM (#13587508)

    I'm not sure if Epic invented it, but I can certainly tell you that microthreading, latent functions (such as the sleep in the door example, or a playanimation method that takes game time to complete), and this general idea has been around since at least the original Unreal Engine in UnrealScript (which is now a rather mature scripting language).

    Go back even further than that. The idea of building a game engine that acts as a virtual machine for scripts defining a game is a very old idea. For example, way back in 1987, LucasArts developed SCUMM [wikipedia.org] (Script Creation Utility for Maniac Mansion), which is little more than an engine that runs scripts the define a game. All of LucasArts' adventure games from Maniac Mansion to The Curse of Monkey Island used SCUMM. After that, they built a new engine (GrimE [wikipedia.org], Grim Edit) that was used in Grim Fandango and Escape from Monkey Island and followed the same ideas they first built in SCUMM. This time they used Lua [wikipedia.org], which is a popular scripting language used by many other commercial game engines (such as Bioware's Infinity Engine [wikipedia.org] used for the Baldur's Gate games, the Icewind Dale games, and Planescape: Torment).

    Unreal's UnrealScript is a very powerful language within the scope of the Unreal engine, but it's certainly not the first implementation of the "game engine as an abstract operating system for scripts" idea. The technology of the scripting language may change, but the core idea is very old (and very good). There's nothing inherently special about using Python as the scripting language for a game, but it's neat that Python is now capable of doing so.

  • by AMK ( 3114 ) on Saturday September 17, 2005 @09:34PM (#13587557) Homepage
    Another game-related Python activity is the PyWeek competition [mechanicalcat.net], where entrants have one week to write a game. Unfortunately you've just missed this year's competition; it's held in August, and the winners were just announced.
  • by Anonymous Coward on Saturday September 17, 2005 @09:51PM (#13587605)
    There are many, many games using python for scripting. Battlefield 2 being the most recent I've noticed.

    Search your game folders for .py files, you may be surprised.
  • by fjb4 ( 176395 ) on Saturday September 17, 2005 @10:29PM (#13587717)
    Battlefield 2 uses Python too (look around in the game's directories, you'll find lots of *.py files). In fact, I'd guess that it's the most widely played game right now that uses Python.
    What's interesting to me is that they were able to utilize Python and still develop a state-of-the-art, performant 3-D FPS. (People with slightly older computers might argue about "performant", but it does actually run very well even with the Pythion compiler/interperter baked in.)
  • by d2ksla ( 89385 ) <krister.kmlager@com> on Saturday September 17, 2005 @10:38PM (#13587742) Homepage
    I use Emacs for editing both C and Python. With Python, it is just a matter of marking the block you'd like to indent/dedent (CTRL-space at the beginning of the block, and ALT-w at the end), and then use "CTRL >" or "CTRL <" to indent/dedent the whole block. This saves a few keypresses compared to C, where the extra braces have to be inserted/removed.
  • Re:Civilization 4... (Score:5, Informative)

    by drxray ( 839725 ) on Saturday September 17, 2005 @11:02PM (#13587817) Homepage
    See the Unreal Tournament Community Bonus Pack [unrealtournament.com], and the SuperStorm [earth2160.com] fan-made patch for Earth 2160. Both hosted on official download sites. The UT2003 community pack was actually included on the UT2004 DVD.

    These are just the two examples I've played today...
  • Comment removed (Score:3, Informative)

    by account_deleted ( 4530225 ) on Saturday September 17, 2005 @11:30PM (#13587871)
    Comment removed based on user account deletion
  • by shobadobs ( 264600 ) on Saturday September 17, 2005 @11:43PM (#13587905)
    I don't like that code either; I'd write

    (define (gnc:leap-year? year)
        (cond ((= (remainder year 400) 0) #t)
            ((= (remainder year 100) 0) #f)
            (else (= (remainder year 4) 0))))

    As the other poster pointed out, Python can be written moronically too.
  • by Anonymous Coward on Saturday September 17, 2005 @11:58PM (#13587943)
    Something is screwed up. "os" is standard (and indeed, one of the most essential standard library modules). If this is broken, no wonder you're having problems.

    Anyway, just like most programs written in other languages, python programs often require dependencies.

    These can often be found in that really useful "README" or "INSTALL" file in the project's top-level directory. You *did* read them, didn't you?

    Almost all python stuff I've used was correctly installed by a meagre "python setup.py build && sudo python setup.py install". Occasionally I'll need to install a 3rd-party package. In which case I repeat the steps above for it. ;)
  • by chromatic ( 9471 ) on Sunday September 18, 2005 @12:08AM (#13587969) Homepage

    You know, tools such as StackGuard, ProPolice, Valgrind, Splint...

  • by DannyKumamoto ( 4636 ) <dnk@@@prismnet...com> on Sunday September 18, 2005 @12:13AM (#13587981)
    With Cell (which I've worked on for 3.5 years until last month), its Power core supports virtualization feature (or "hypervisor" mode as IBM likes to call it) as documented in Power Architecture V2.02 [ibm.com].

    This allows companies (I won't be surprised see if all 3 game consoles will support this) to allow game programmers to create RTOS (real-time operating system) like programs so that they have very refined control over program behavior (even OS like control) while the hypervisor SW (like Xen) will prevent any critical resources of games from clobbering each other (just as hypervisor supported OS will not hurt other OS running under hypervisor). Virtualization will give more control to the game programmer (more power and more responsibility) while the game console maker would retain minimal but critical control over the resources (mainly IO and memory). Pretty exciting world ahead for game developers in my opinion....
  • by John Whitley ( 6067 ) on Sunday September 18, 2005 @12:14AM (#13587986) Homepage
    FWIW, it's also trivial to do the same thing under Eclipse using PyDev [sourceforge.net]. Mark a block of text, then hit tab or shift-tab to indent/unindent. If you're an Emacs user, turn on Eclipse's built-in Emacs keybinding set and it's home away from home...
  • by nobodyman ( 90587 ) on Sunday September 18, 2005 @01:17AM (#13588165) Homepage
    Never messed with Lua but if thats all a coroutine does then your comparison is absolutely correct. However, after reading the article it kind of sounds like the threading model of Stackless Python shares more with a Lua coroutine than with threading as how we think about it in the OS world. From the article:
    The only solution is non-preemptive multithreading. This necessity also solves many synchronization problems. A non-preemptive environment rarely needs locks and can be deterministic.
    Which sounds to me like thread2 doesn't start until thread1 completes execution of a routine (or explicitly calls sleep() ).

    Not a knock against Stackless Python, though. In fact, I agree with the author that preemptive threading in the context of scripting a game probably causes more problems than it solves. In a game, you can be more trusting of its processes/threads(aka scripts) than a general pupose OS would be. On the other hand, with games like UT where you can have have multiple "mutators" running simultaneously that were created by the modding community and not an inhouse designer, maybe preemptive threading would be a good idea.

  • by GileadGreene ( 539584 ) on Sunday September 18, 2005 @01:54AM (#13588266) Homepage
    Well, Stackless itself implements "tasklets" (lightweight threads) using a round-robin scheduler (which does not schedule tasks that are blocked on channel communications) - see here [stackless.com] for more. This approach was apparently heavily influenced by things like CSP and occam.

    I have to admit that I'm not clear on what the original article means when they talk about using non-preemptive multithreading (do they mean somehow overriding the Stackless tasklet scheduler?). They seem to be worried about the need for locks on shared-state variables. However, the correct approach to building a Stackless-based system would probably be to follow the CSP paradigm of avoiding shared-state completely - such systems are lock-free and can be completely deterministic. But perhaps I am completely misinterpreting what they are trying to get at.

  • Eve Online and BF2 (Score:2, Informative)

    by VC ( 89143 ) * on Sunday September 18, 2005 @04:42AM (#13588605)
    Eve online (crowd control software) is the main user of stackless python. Most of the patches are either contributed by them or requested for them. BF2 also uses python for most of its non engine work. (not sure about the AI though.)
    Rock on python.
  • by rg3 ( 858575 ) on Sunday September 18, 2005 @06:05AM (#13588736) Homepage
    The oldest one I remember was Severance: Blade of Darkness. It ran perfectly in a P3 500. Released in 2001. It also featured some really revolutionary graphics and other technologies. For example, real-time lights like in Doom3 except that not so-well done and with more restrictions; and also a physics engine. Sorry for being a little off-topic here, but that game impressed me when it was released.

    http://www.codemasters.com/severance/eng/ [codemasters.com]
  • by Anonymous Coward on Sunday September 18, 2005 @07:44PM (#13592165)
    Neverwinter Nights, KOTOR 1/2 and Far Cry used Lua.
    Battlefield 2, Blade of Darkness, Eve Online used Python.

    These are real-world examples you can mess with right now, rather than speculating about which is better.

    I kind of like Python more than Lua because the syntax is more straightforward, which is good for non-technical level designers. I'm sure programmers will have other opinions, but what's the point of using scripting if it's going to be as difficult as C++? Does it really save that much time?
  • Re:Oooh! (Score:1, Informative)

    by Anonymous Coward on Monday September 19, 2005 @03:28AM (#13594123)
    In reply to the other replies to the parent: I think he's talking about the fact that classes are implemented with hash tables. If you make a method call, the runtime has to do a hash lookup before it can actually dispatch the call. (If you thought it was slow to call a C++'s virtual member function, wait 'til you try Python. You won't ever call C++ slow again.)

    A "more sensible" implementation would involve using type declaration/inference to allow compile time resolution of member functions. Even if it only managed to resolve a pointer to a pointer, it would still be at least several times faster. Unfortunately, that would defeat one of python's major selling points: dynamic classes. Thus, it's not really such a sensible option.

    So in conclusion I can't really suggest a solution, but I thought I'd at least try to explain the problem.

"Experience has proved that some people indeed know everything." -- Russell Baker

Working...