|
|
| A Scripting Language. |
|
Marcello
Member #1,860
January 2002
|
I know this has been asked before, but I want to approach it from a slightly different perspective. I'm working on 2 games at the moment, a project I'm leading, and one my friend is. I'm thinking that it'd be advantageous in both to have a scripting language to control level layout/design, and cut scenes. So I have a couple questions, the first would be which language to use. The ones I've looked at, but haven't tried to implement are: Lua I mention Lua because it's come up numerous times, but from what I've seen, the scripting language itself is hideous, almost basic-esque, and I really need a c or java style scripting language. If people are just recommending that one cause it's popular, that doesn't help me. I'd like to hear some pros/cons in comparison to the other languages. Small is an interesting language I read about somewhere on this site, the fact that it has a compiler is a nice advantage (I really need a language that can work with compiled files so they're both smaller, faster, and slightly more difficult to modify). I started looking at the code examples, however, and it seems to have a number of rather odd syntaxes that are not from c, so I'm not sure how much I like it. I don't know anything about object c. Spidermonkey comes up because I love javascript, I think it's a great scripting language and the ability to extremely quickly design stuff in a very loose syntax sense is great. The main cons I see here are that it seems complicated to implement (although I haven't tried yet), and I haven't figured out if it has any kind of compiling system (it can compile at runtime, but I'm not sure about saving compiled bytecode). Java, most likely this isn't a good choice, simply because it's so complex and has a lot of overhead. I might as well code the whole game (sans graphics) in java if I went that route. Plus it has to be compiled to use, and that makes dev time slower. Python, don't know much about that, but I've look at the language a little when looking at jython. And last of all, I could go all out and bug one of my friends to code me up a custom scripting language. Obviously this solves any possible problems I have, but takes longer, and perhaps is less reliable. There are certain advantages to using a knowing scripting language (though I'd probably try to get it based around javascript). Ok, so that's part I. To decide on the language, it really depends on how I use it. In a nutshell I need for sure some kind of OOP system, so I can have objects for enemies and call functions on them and whatnot. I don't want to be using global namespaces for all the functions, since that makes the scripts uglier and harder to manage. The second part is how I should go about using the scripting language. I'd like to give level design quite a bit of control through scripting languages, such as enemy placement, setting up default parameters for them. Similar things could be used for cut-scenes, loading in characters, telling them where to move and displaying speech and whatnot. But should I go so far as to have animation loading, playback, and enemy movement coded in scripting language? Obviously with a powerful enough scripting language it's not a problem of how to do this, or even repeated code, but whether the speed is there and if it's worth doing it that way. I should note that these are both fairly big games, and will most likely be released as shareware of some sort, so licensing issues are also important. I'd favor the cheapest solution (not including own time). So I think that about covers it, to sum up, which languages have you used and/or recommend, why, and how much do you use them for? Thanks, Marcello |
|
Korval
Member #1,538
September 2001
|
Lua is actually quite C-like, once you get to know it. Lua scripts can be compiled, so that you can load compiled scripts rather than compiling at run-time. Also, Lua 5.0 has classes and inheritance. Via the LuaBind add-on, you can even give Lua a base class, let it derive a class from it, and then derive a class in C++ from that Lua-derived class and use it like a (mostly) regular C++ class. Kinda nifty. Python is designed from the ground-up to be object oriented, so its OOP syntax is probably a bit cleaner than Lua. I've always felt that the primary determinant with scripting languages that have decent syntax is the code-to-script interface. Via LuaBind, this interface can be made virtually transparent under Lua. I have no idea what Python's or Small's code-to-script interface is like. |
|
Marcello
Member #1,860
January 2002
|
-- for comments and lack of {}'s is pretty bad. [edit]I was looking at http://www.lua.org/manual/5.0/manual.html#2 and I've decided I really can't stand that language, it's just too similar to languages I hate, and it's really stupid to use two different languages for the same problem (I have enough trouble switching between java, c++, and php as it is) Marcello |
|
Carrus85
Member #2,633
August 2002
|
python would be great, assuming you can get it to integrate with your program ok. It is a really stable language, and is quite easy to debug, which is what you want in a script, correct? True, the significance of whitespace at the beginning can get quite annoying, but you get used to it after about 5 minutes. It also has a really short learning curve as well...
|
|
Peter Wang
Member #23
April 2000
|
Marcello, don't judge a language by its syntax (... unless it's perl). You said you liked Javascript, Lua is really very similar.
|
|
Korval
Member #1,538
September 2001
|
Quote: -- for comments and lack of {}'s is pretty bad.
Yeah, scripting languages aren't supposed to be more readable or anything If you want to use C-syntax, why not just use C? Why bother with scripts at all? |
|
Marcello
Member #1,860
January 2002
|
Quote: Marcello, don't judge a language by its syntax (... unless it's perl). You said you liked Javascript, Lua is really very similar. What else is there to judge it upon? But I'm not asking people to defend lua, which is all I'm getting here, I want to know the alternatives and for example, what makes lua better/worse than them. Quote: Yeah, scripting languages aren't supposed to be more readable or anything Well designed clean code in any c style language is quite readable. I'd like to say that for all languages, but perl is one of probably many exceptions. Surely you agree that learning a entirely new and different syntax just for a freaking scripting language (I mean, wtf is ::= or :== wtf... that's just messed up). Quote: If you want to use C-syntax, why not just use C? Why bother with scripts at all? That's a silly question. I'm not gonna hardcode the levels, that means the level design can't be separated from the coding. That means more debugging, slower level design, and it requires someone who can code in c AND knows how to compile, link, etc. with the rest of the what could quite possibly be incomplete or in development source code. If it's all offloaded to a scripting language, it means more control, more separation, and frankly, cleaner code in the end. Marcello |
|
CGamesPlay
Member #2,559
July 2002
|
And extensibility drops to rather near nil, because you can't go around distributing DLLs for new levels.... I doubt people would like that -- Ryan Patterson - <http://cgamesplay.com/> |
|
Zaphos
Member #1,468
August 2001
|
I can say that python has been used at least once in a professional game dev environment: disney's prime 3d Game Engine (now partly open sourced at http://www.etc.cmu.edu/panda3d) seems to use it heavily. So it's probably going to be viable in terms of efficiency and etc for whatever project you may be conceiving. And it's a very well developed and well liked language, and it's known for being pretty ("pseudo-code that compiles"). And it seems to have been designed around, and to support with tutorials and docs, methods of interacting with C/C++ code. Soo ... you may want to give it a closer look. As a side note I would say that a script being "slightly more difficult to modify" is not exactly a good thing; imo the more accessible your game is to modder types the more likely it is to have a loving fanbase and etc. Can't see why this is such a bad thing. But if you're really worried about it you could try encrypting the files and naming them oddly, which (though obviously not perfect) should keep away idle prying while only slightly increasing load times. Anyway, take my advice with a grain of salt, of course; I'm no expert -- |
|
Marcello
Member #1,860
January 2002
|
Actually it's more of a problem of modding the scripts to cheat at the game and get ahead. It's not a big deal, but there are obvious speed benefits to compiling beforehand, for example if there are lots of comments and excessive syntax, there's no point in extra load time. Marcello |
|
Zaphos
Member #1,468
August 2001
|
Quote: Actually it's more of a problem of modding the scripts to cheat at the game and get ahead. Well, I suppose you could always, in the final release, have the main level files encrypted but also include some mechanism for providing seperate, different level files / config files. Definitely if you're going to have an extensible program, it'll be worth it to consider adding a mod system Anyway, as another plug for python, it does do the bytecode for fast loading thing, just in case you didn't know. -- |
|
Korval
Member #1,538
September 2001
|
Quote: I mean, wtf is ::= or :== wtf... that's just messed up You didn't understand what you were reading. I can understand that, because it took me a while to figure out that the ::= stuff wasn't part of the language. The document you were reading is a very technical document about Lua; it specifies the language as a grammar. Unless you understand how to read a grammar (and I don't mean as in English grammar. I mean a descriptive grammar), some of the symbols they use can confuse you. ::= isn't part of Lua. They just use '=' like everybody else. When the document says something like, "var ::= Name", what they mean is, "The concept of a variable is defined by a thing called a 'Name'". When they say, "stat ::= for Name `=´ exp `,´ exp [`,´ exp] do block end", they're saying that the stuff after '::=' is a statement. Really, the Lua manual sucks for learning the actual language. I'm of the opinion that the manual is why Lua isn't nearly as widely used. It's best to take a look at functioning Lua code. Quote: That's a silly question. I'm not gonna hardcode the levels, that means the level design can't be separated from the coding. With dynamic linked-libraries, this is not the case. You can easily build "scripts" as plugin-type .DLLs. In fact, it would be much easier than the simplest scripting system, because it is just native C/C++. Quote: That means more debugging If you're writing low-level C. But, good, protected, high-level C++ can be just as "bug-free" as a scripting language; ask to Gillius about that. However, more importantly, when something needs debugging, it gets debugged with a C/C++ debugger. I know of no scripting language that has a debugger that can compete with VC++. As such, when a script does have a bug in it, it is much easier to solve in C/C++ than in a scripting language. Quote: slower level design Bah. Why is it any slower? Granted, it depends on what the script is supposed to do. An AI script will look a lot like C, but a map script (that tells the system where to spawn things, for example) written in C is pretty ugly, since it really is just a list of strings and positions. Of course, this argues against a C-like syntax in your scripting language. <quote>and it requires someone who can code in c AND knows how to compile, link, etc./quote] Well, they need to code in C in order to deal with your C-like scripting language, right? Also, compiling is simple: press F7. If it's more complicated than that, get better compiling tools. Quote: with the rest of the what could quite possibly be incomplete or in development source code. Hence the .dll paradigm. Quote: If it's all offloaded to a scripting language, it means more control, more separation, and frankly, cleaner code in the end. Actually, it means less control. Because you're programming in a limited scripting environment, you can't do all of the little low-level tricks that a C program could; that has to be offloaded to other code. .DLL's give you just as much separation as an actual script. As far as clean code is concerned, it is uglier to bind to a scripting language. As clean as LuaBind is, it is still cleaner to not have the LuaBind commands/variables that bind the class to Lua. These commands, whether they are LuaBind, the Lua API, the Python API, etc, are layered on top of an existing class interface; an interface that could be directly used by a .dll. As such, the .dll interface is the cleanest you can possibly get. It has the bare minimum code: a C++ interface. As such, the advantage of using a scripting language at all is ease of writing the game. Your scripting language should make it easier at the given task than C/C++. Otherwise, just build a .dll interface and leave it at that. |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: ... unless it's perl
DIE! -- |
|
Richard Phipps
Member #1,632
November 2001
|
Korval, you're argument makes a lot of sense. I've never thought of it that way before. So, yes I can see the advantages of using a .DLL file. I agree with you on this one. |
|
Thomas Fjellstrom
Member #476
June 2000
|
Anyone who thinks "LuaBind" is a clean interface is at least as crazy as I am. -- |
|
Evert
Member #794
November 2000
|
Quote: Anyone who thinks "LuaBind" is a clean interface is at least as crazy as I am. So you do think it's a clean interface then? As for using DLL's - my opinion is that you're unnescessarily restricting yourself to people using one particular operating system, so I'd recommend against it for that reason. As I understand it, one of the advantages of using a scripting language is that it does not have to look like C, but can be more high-level. Have a look at Amit's page for some (old?) links and discussions on scripting languages. |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: So you do think it's a clean interface then?
No, I'm just crazy -- |
|
Korval
Member #1,538
September 2001
|
Quote: Anyone who thinks "LuaBind" is a clean interface is at least as crazy as I am. It doesn't get much cleaner than LuaBind, really. Just create this templated thing that looks surprisingly like a class declaration, and you're done. It's all template meta-programming magic and so forth that is completely hidden from your code. The only way an interface can be cleaner is if it reads and parses C/C++ and can just take a class and turn it into an interface without any added code. Quote: As for using DLL's - my opinion is that you're unnescessarily restricting yourself to people using one particular operating system, so I'd recommend against it for that reason. You can use Linux .so's, too. You'll have to do a little #ifdef'ing around the code that actually loads the .so/.dll files (since it's OS specific), but after that, the interfaces are all the same: you get function pointers and call functions via them. Any platform worth developing a serious game on has some form of dynamic linking, so the paradigm will work on any modern platform. |
|
Zaphos
Member #1,468
August 2001
|
Hmm ... one advantage of a scripting langauge is that ideally you will be able to change the script code very quickly and while the engine is running (much less significant compile time pauses, etc) such that you can tweak scripts and such in real time, and quickly. I would guess you lose this in a .dll approach; the process of recompiling the scripts and such would probably slow the tweak process by a somewhat relevant amount. -- |
|
Korval
Member #1,538
September 2001
|
Quote: one advantage of a scripting langauge is that ideally you will be able to change the script code very quickly and while the engine is running (much less significant compile time pauses, etc) such that you can tweak scripts and such in real time, and quickly. I've yet to see a scripting system that will actually re-load the script in the middle of using it. After all, it's not like the interpreter is constantly reading the script file from the disk. Also, since the script is running at the time (it may have instanced classes and variables and so forth), changing it without restarting could very well have highly negative consequences. At the very least, the domain of the script needs to be restarted. If it is an AI script, the AI character should be respawned. If it is a map script, the map needs to be reloaded. Quote: and there do seem to be commercial, fully-featured ides for it For $150-200. Hardly a reasonable price for a scripting language IDE. I would have been willing to go with $50 or so. |
|
Thomas Fjellstrom
Member #476
June 2000
|
I don't know, once I finally get my VM done (ohy...) it wouldn't be hard to reload a script everytime its saved. Not a big deal if you just replace the code. There can be problems, but that should be expected. -- |
|
Marcello
Member #1,860
January 2002
|
Also imagine having a console in the game that lets you run commands, load/reload scripts at runtime. I think I'm gonna try spidermonkey, see how difficult it is to implement. Mainly because it's my favorite scripting language. :-) Marcello |
|
nonnus29
Member #2,606
August 2002
|
Marcello, I thought you would have usd rhino in your java apps anyways.... |
|
Korval
Member #1,538
September 2001
|
Quote: Also imagine having a console in the game that lets you run commands, load/reload scripts at runtime. Any serious game should have a console in it for entering commands. That's a vital debugging tool. |
|
Zaphos
Member #1,468
August 2001
|
Korval said: For $150-200. Hardly a reasonable price for a scripting language IDE. I would have been willing to go with $50 or so. I'm guessing that there are IDEs in the $50 price range as well, and I wouldn't be surprised to see one for free, either. I'm simply not using python enough yet to make it worth searching around. I didn't mean to imply that that was the only IDE for python with an graphical debugger; it was just meant as a demonstration that such things exist for the language. Quote: I've yet to see a scripting system that will actually re-load the script in the middle of using it. Jesse Schelle (developer of Toontown Online, works at CMU's Entertainment Technology Center) mentioned exactly this kind of action in an IC speech (as part a freshmen CS course [IC] that is basically a lecture series meant to define CS through examples; features basically a researcher a week explaining what cool stuff they work on). So I think the technique is certainly feasible. Annnyway ... good luck, Marcello! -- |
|
|
|