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."
Console Games? (Score:4, Insightful)
I don't see what is so new about this "news". Console games are designed with the idea in mind that the hardware does not have a full featured OS. We have to do almost everything, from memory management to thread syncronication, and guess what are the "processes" we are working on....? Is this a news story because noone has actually put this concept into words?
Re:Console Games? (Score:2)
Re:Console Games? (Score:5, Funny)
Syphilis in 3D? (Score:5, Funny)
Re: Syphilis in 3D? (Score:3, Funny)
> Ewww!!!! Oh I misread... Whoops...
You can tell they're not marketing to us dyslexic types.
Re: Syphilis in 3D? (Score:2, Funny)
Re:Syphilis in 3D? (Score:3, Funny)
Jeb
President
Gon-o-Ria Inc.
Civilization 4... (Score:5, Interesting)
Re:Civilization 4... (Score:2)
Keep dreaming. There isn't a legal department in the country that would sign off on that. Typically, if you send unsolicited ideas to an IP maker they discard them unread just to avoid liability.
Re:Civilization 4... (Score:5, Informative)
These are just the two examples I've played today...
Re:Civilization 4... (Score:2)
Re:Civilization 4... (Score:3, Funny)
"In RIAA/MPAA/IP America... "
"... The industry owns YUO!"
"... The mon(k)ey TALKS!"
"... Freedom as owns YUO"!
Re:Civilization 4... (Score:2)
Re:Civilization 4... (Score:2)
Offering the content is perfectly possible legally, they can waive responsibility via a EULA or just offer it as 3rd party content not directly supported by the company.
Python is nice but consider LUA for game scripting (Score:5, Insightful)
If you are thinking about scripting languages for your games consider LUA. http://www.lua.org/ [lua.org]
Re:Python is nice but consider LUA for game script (Score:5, Informative)
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.
Dataflow Languages (Score:2)
The channels description made me think of Dataflow languages [wikipedia.org]. I'm not very educated in this area; would you agree that they are very similar, or am I way off here? Thanks.
Re:Dataflow Languages (Score:2)
Note that it is possible to implement a state-free, dataflow-style program using a CSP-like language. But the stateful style is much more
Re:Python is nice but consider LUA for game script (Score:2)
Coroutines are not the same as threads. Coroutines provide what is essentially sequentially executed (i.e. single-threaded) functions with preserved state between function calls. This is not at all the same as the interleaved execution of mutliple threads of control that a truly concurrent system provides. Please do not conflate the two.
just a nitpick to counter... (Score:3, Informative)
Which sounds to
Re:just a nitpick to counter... (Score:3, Informative)
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 loc
Re:Python is nice but consider LUA for game script (Score:5, Interesting)
Although Lua didn't use much memory, I found it allocated and freed lots of memory. Lots and lots of it. This had the nasty side effect of fragmenting memory to all hell. This can be fixed by giving it its own stack, but its still an issue, especially if the LUA calls out to something that needs to allocate memory. It can get very nasty, very quickly. In addition, I found the language syntax to be fairly poor, I mean it was designed with configuration files in mind, and so it works great for configuration files, but it syntactically didn't fit with most of the AI we wanted to do. We just ended up calling C most of the time anyhow. On top of that, the use of LUA meant we didn't have a decent debugger (if any), which meant tracking down crashes and bugs was an adventure in tedium, using lots of printfs.
Python was a language better suited to Game AI, but once again, memory fragmentation was a big big issue. In addition, it was fairly slow and tended to access lots of memory, which killed the cache on most of the consoles nicely.
Overall, with all the performance considerations aside, I found the choice of Python and LUA to be poor mainly because they didn't solve the problem that they meant to address. One of the big things that everyone wants is non-programmers being able to edit game behavior. Both Python and LUA may seem easy to those of us who code, but it is incredibly difficult for most game designers, as most of them can not code at all. Generally, in the course of development, there isn't time or motivation for people to learn how to do many new things, and so the programmers end up doing most of the scripting. Once the programmers are doing the scripting anyhow, you may as well do it in C or C++, as you'll have better development tools. The other big argument I hear is that you can update AI in realtime, which sounds great, but in practice, is much more difficult to do than it sounds. If you are going to add scripting for this feature, then make sure if you can't implement the feature, then remove the scripting. You'll save yourself a ton of trouble. Anyhow, I'm sure lots of people will post examples of projects that succesfully used these scripting languages, and I'm sure there are some, but it certainly hasn't for any of the console based projects I've worked. Which isn't to say there aren't scripting style solutions that do work, I've seen them work and am a big proponent of them, but I haven't seen any that worked with a general-purpose scripting language. Remember, there is a price to be paid for it being general purpose, and if you have a specific purpose in mind, that price can be very high.
Re:Python is nice but consider LUA for game script (Score:2)
WHAT?!?!?!?
C//
Re:Python is nice but consider LUA for game script (Score:2, Informative)
You know, tools such as StackGuard, ProPolice, Valgrind, Splint...
Re:Python is nice but consider LUA for game script (Score:2)
C//
Re:Python is nice but consider LUA for game script (Score:3, Insightful)
Python's popular enough to have a lot of good tools (IDEs, debuggers etc.) and, IME, a lot easier to write code for than C++. You can do things in a lot less programmer-time and a lot less LOC, and it's more readable for maintainability. I would recommend using python for anything not performance-critical, not just AI scripting. And for those designers who do have the time and mot
Re:Python is nice but consider LUA for game script (Score:2)
What has served me well in my career is rather than coming up with tools that I think would be useful, its better to ask the end-user, the artists and game designers, what their ideal tool would be. If they say "something like P
in other news (Score:2)
seriously, low-level programmers dealing directly with memory, registers and GPUs will never get the benefits of very high programming languages... like writting far better and more flexible NPC AI behaviour in far less time.
Re:Python is nice but consider LUA for game script (Score:5, Funny)
EVE Online (Score:5, Informative)
Other games that use Python (Score:2)
Battlefield 2
Nexagon: Deathmatch
Toontown
Blade of Darkness
Freedom Force
Temple of Elemental Evil
There are probably other games out there. I'm not sure which use stackless Python,though, as I don't know what stackless Python is. At any rate, people have been finding it useful in games for awhile and that's not likely to stop any time soon.
Re:Other games that use Python (Score:2)
It uses the open-source multi-platform Panda3D http://panda3d.org/ [panda3d.org] engine.
And the SourceForge http://sourceforge.net/projects/panda3d/ [sourceforge.net] link, the Helix community https://panda3d.helixcommunity.org/ [helixcommunity.org], etc.
Works pretty well, 10K+ players.
Re:EVE Online (Score:2)
(Don't get me started on their backend design and management....)
This is not a new idea (Score:5, Informative)
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).
Re:This is not a new idea (Score:2, Informative)
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,
I can trump both of you whippersnappers! (Score:2)
Okay, okay... the "scripts" were really just an array of bytes that had opcodes defining where to turn, when to shoot, etc. etc.. I agree that the idea of scripting parts of your game is not a new idea, but the article is still a good read.
Besides, I don't think that anyone (even the author) is trying to sell scripting as a new idea. Rather, I think what *is* new is that general purpose scripting languages are starting to
Lua, Books (Score:5, Informative)
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)
Re: (Score:3, Informative)
Python? For 100s of game entities? Try Mono... (Score:4, Informative)
There's a REASON they're using Stackless (Score:4, Informative)
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.
Re:Python? For 100s of game entities? Try Mono... (Score:2)
Another one of those weird reads. (Score:3, Funny)
Did anyone else read that as "Syphilus3D"?
Open Games (Score:4, Insightful)
But only for programmers. We're still struggling with IPC facilities for programmers, and runtime IPC is rudimentary. Some programs don't even have pipeable STDIO. But if every app's GUI (or CLI, or other UI) always had an equivalent API, we could much more easily program them. We programmers should establish this pattern ourselves, ensuring every menu item, dialog box and UI buffer has a public API that can easily be wrapped in Python, C/++, Perl, Java or other calling wrappers. And bundle scripts with our distros that "kiddies" can easily hack into new versions.
We can leverage our "Open" culture from our programmer ghettoes to the user community at large. And since we're even more often users than programmers, we're immediately serving ourselves, too.
Re:Open Games (Score:2)
Re:Open Games (Score:2)
And, yes, we do need COM for Linux, but what the parent said is much more than just COM; it's also a set of introspection facilities on top of it, and support tools, and,
And when we do, exactly what the parent said will happen: Programming will lift out of the programmer ghetto.
Re:Open Games (Score:2)
That said, what the parent was talking about was a bit more.
We need more than just an IPC system between components; We need an infrastructure on top of that IPC system that allows for:
Look at DCOP (Score:2)
Naughty Dog Used Scheme for this (Score:3, Interesting)
They had Franz lisp make it for them -- this I found out at gamasutra.com
I think the only big deal about this is that they use Python, as opposed to some other language.
Actually, Naughty Dog Used Common Lisp (Score:2)
Not limited to Python. (Score:5, Interesting)
TFA is talking about the use of coroutines to avoid programming state machines. Coroutines are really very useful, as they allow code as simple as the following:
The code, which is supposed to make an airplane actor fly a looping maneuvre, is much simpler than the corresponding state machine code, which would consist of four states. I used this sort of programming in my hobby flightsim project Thunder&Lightning [tnlgame.net] using this [ds9a.nl] C++ implementation of coroutines. There is also Io [iolanguage.com], an embeddable language with a very small footprint which is easy to learn and nice to program with and which supports coroutines as well (actors in Io's terminology).Oooh! (Score:2, Interesting)
Re:Oooh! (Score:2)
Freedom Force used Python and ran just fine on my gigaherts Duron sneeze pump.
What is so fucked up about it ?
Fucked up hash table implementation? (Score:2)
You know, not every part of the code of a program (even games) needs to be super-asm-style-optimized. You only have to find your bottlenecks and optimize them (You can easily mix
Re:Oooh! (Score:2)
Python to C++ Automatically (Score:4, Interesting)
Check it out:
http://shed-skin.blogspot.com/ [blogspot.com]
http://sourceforge.net/projects/shedskin/ [sourceforge.net]
Re:Python to C++ Automatically (Score:3, Funny)
Amazing. They've invented the compiler.
Python game programming competition (Score:3, Informative)
Erm... (Score:4, Funny)
Python Already in Use for Commercial Games (Score:2, Informative)
Search your game folders for
Re:Python Already in Use for Commercial Games (Score:2, Informative)
http://www.codemasters.com/severance/eng/ [codemasters.com]
Ogre 3D engine and Python (Score:5, Interesting)
Last weekend I pulled in the latest Python (2.4.1) for Winblows, the Ogre 3D engine binary , and PyOgre (http://www.ogre3d.org/index.php?option=com_remosi tory&Itemid=57&func=selectcat&cat=1 [ogre3d.org]).
This combo rocks fairly hard.
Run a 27 line Python script, and boom, you're looking at a working 3d engine. It's fast, too, probably because the heavy lifting is being done in the Ogre runtime binaries.
For developing and prototyping, there's no time wasted (re)compiling changes; tweak some Python and away you go. And there's no reason the code or scene objects can't be tweaked while the engine is running, perhaps by means of a some sort of IPC, whether it's via a telnet/socket-type connection, or an XML-RPC daemon process, or whatever. Some people have even worked up demo on-screen overlays akin to the Quake console.
I'm looking forward to the day I can interact with a 3D environment and manipulate 3D objects with the same immediacy I'm accustomed to manipulating data in the Python interactive prompt. Heck, I'd even learn Smalltalk if they plugged Ogre directly into something like Squeak. But for now, Python + Ogre (PyOgre) seems to show a lot of promise.
Don't forget that Battlefield 2 uses Python (Score:2, Informative)
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.)
Virtualization and Game as OS (Score:3, Informative)
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....
Buddy. (Score:3, Funny)
The Fall (Score:2)
This could have happened with other languages, but using Python did not prevent them from producing crappy code.
so this is new now (Score:2)
Re:so this is new now (Score:2)
Eve Online and BF2 (Score:2, Informative)
Rock on python.
Re:Lisp instead of Python (Score:5, Insightful)
Re:Lisp instead of Python (Score:2)
Re:Lisp instead of Python (Score:3, Informative)
(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.
Re:Lisp instead of Python (Score:2)
$answer = ($year % 4) == 0 ? ""
($year % 100) == 0 ? "n't"
($year % 400) == 0 ? ""
"n't";
print "\n$year is$answer a leap year.\n\n";
Oh
Re:Lisp instead of Python (Score:2)
Oh geez I am dumb. It must be late. Coulda always made it a sub and checked to see if it was >= 1900
Re:Lisp instead of Python (Score:2)
Re:Lisp instead of Python (Score:2)
It's compiled to bytecode, like Java. Just FYI.
C//
Re: (Score:2)
Sure it does... (Score:2)
Certainly there are many differences between Python and Java at the language level. When it comes to compilation, though, they're basically the same.
Re: (Score:2)
Re:Lisp instead of Python (Score:2)
Congratulation, you're a failure, py2exe doesn't compile shit it merely embeds both a Python interpreter and your software (along with the required libraries) into a single exe
Python whitespace indentation (Score:3, Insightful)
Re:Python whitespace indentation (Score:2, Insightful)
Auto-indenters are just tool for re-arranging indentation based on brace structure.
If there is no brace structure, then there is no need for auto-indenters.
The fact that the same information is being represented in two ways-- as the brace structure, and as the indentation-- is the problem that auto-indenters are designed to solve. This problem does not exist in python.
Re:Python whitespace indentation (Score:2)
Let's say in C you have this:
while(foo) {
do_stuff();
}
now it turns out that you want this to be optional. No problem:
if( enable_do_stuff ) {
while(foo) {
do_stuff();
}
}
Now it looks a bit ugly, but no problem, hit a button and it's automatically indented. But since python has no braces, you need to do the indentation manually.
There's a potential bug there as well, in that you need to make sure that you correct the indentation correctly, or it d
Re:Python whitespace indentation (Score:2)
Re:Python whitespace indentation (Score:2)
Yes, and those editors also have auto-indent, so why does Python force one to those non-automateable indentions in the first place?
### You just have to pay attention to this with python, just like you pay attention to braces in C.
One doesn't have to pay attention to braces, since they don't break with copy&paste.
Re:Python whitespace indentation (Score:2)
True, that problem doesn't exist in Python, the problem that exist in Python however is *FAR* worse. While code that gets crudly copy&pasted into C might not look pretty, its easily fixed with a single button press, code that gets crudly copied in Python actually does break and does the *
Re:Python whitespace indentation (Score:2)
Re:Python whitespace indentation (Score:3, Informative)
Re:Python whitespace indentation (Score:3, Informative)
Re:Python whitespace indentation (Score:2)
Pardon me, your exhalted highness, Lord Ender. I too have seen dozens of rants about whitespace, and I agree with you that mostly they are pointless. I find most of the complaints I read about the whitespace in Python to be pretty silly, the answer generally being "well duh, get a better editor". But I've not seen anyone mention the issue I raised above, which isn't solved so easily just by getting a better editor. Basically in a nutshell you could just phrase it as auto-indent not working so well.
Re:Lisp instead of Python (Score:3, Insightful)
At the place where I work, tabs are always 8 spaces. There's a reason for that-- it's because we need to look at each other's code!
As far as newlines are concerned, I believe python accepts any of the popular 3 styles of newline. So that is never an issue.
I'm pretty t
Re:Lisp instead of Python (Score:2)
Re:Lisp instead of Python (Score:2)
Also, I don't get your point about there being too many incompatible object systems. If you have the lambda calculus and static scoping, in any form (even ML), building an object system takes a few pages of code. It is such a s
Re:Lisp instead of Python (Score:2)
Maybe I even use macros to translate the one object notation into another, to avoid having two object systems.
Re:Lisp instead of Python (Score:2)
And as far as I know this hasn't deserved Python too much in the past, and you are allowed to mail Guido or talk to him on the MLs you know...
And given the fact that Lisp is probably one of the most powerful languages out there, "moving towards lisp" seems to be the common factor of each and every progressing language. As long as Python keeps being more readable than lisp I don't quite see the issue (yes I cou
Re:Either I forgot to do something, or Python is.. (Score:2, Insightful)
Re:Either I forgot to do something, or Python is.. (Score:2)
Why ? I've never run into any version incompatibilities. Sure, some modules spit out a string of deprecation warnings when I use them, but who cares ?
Blame Python? (Score:2)
Re: (Score:2, Interesting)
Re:Either I forgot to do something, or Python is.. (Score:3, Interesting)
You did something wrong. Python works perfectly on my system.
Most Linux programs that utilize Python that I've downloaded, didn't work; there's usually a missing, necessary Python module the program needs which either requires downloading from an obscure site or doesn't seem to exist at all from Google searches,
Most C/C++ programs have a missing library which requires the same steps. Your package manager ough