Archived

This topic is now archived and is closed to further replies.

Kylotan

Examples of the benefits of using scripting languages

Recommended Posts

Kylotan    10008
I know that the accepted wisdom is that using a scripting language makes your development go a lot more quickly. But I can''t really think of many examples right now, and therefore am loathe to begin on the path of integrating Python or Lua with my existing projects unless I can clearly see the benefits. I find Python a little simpler to use than C++, but not so much so that it would save me a lot of time, especially once integration time was taken into account. But I''m willing to be proven wrong, so can anyone with experience of this post an example or two of how it has helped them? [ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Ready4Dis    180
What if you had 6 montsers, you wanted one to come straight at you, one to circle behind you, one to stand his ground and wait for you, another to try snipering you, etc, etc. If you have a scripting engine, you can have them do this without modifying code, which means, your artists/level designers don''t need to have a hold of your code, other people can produce enemies for you, without needing code, etc. Also, what if you wanted to add a new weapon? You might want to use a script to define how the gun works, or a script that could handle what sound effects happen at what points on a board, etc. Of course this can all be hard-coded in, but then it''s just not as flexible for end users or your own level designers to play with.

Share this post


Link to post
Share on other sites
Extrarius    1412
Scripting makes things faster because you don''t have to recompile after every change. Large projects can start taking a LONG(hours) time to compile, and if you have all the logic scripting it only takes 30 seconds to make a change and see how it works instead of the time to compile and link.

Another benefit is that it allows 3rd parties to make modifications to your game which is becoming more and more popular with FPS. Some very high-quality mods have come out for most of them, which continued their success for a long while.

Also, as Ready4Dis said, it allows more customization in level files, so you don''t have to hard-code each level. If you want something to happen in a map, you open up the script editor and type in a few lines and it''s done. No need to open up the full source for the engine and make a new function Level_205228() to handle the custom stuff for that section.

Share this post


Link to post
Share on other sites
Kylotan    10008
Ok, I should have made this clear, but forget 3rd parties (including in-house 3rd parties such as artists and designers) as they aren''t part of this particular equation. I''m thinking purely in terms of development speed.

My largest project to date takes 5 minutes to do a full recompile. This is not insignificant, but then I rarely need to do a full rebuild because I''m not too bad at managing my dependencies. So it could help here, but since I rarely spend more than 2 minutes on any given compile, and would spend at least several hours integrating a scripting language, I believe it would be a long time before this single aspect would benefit me.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I was going to use Python as a scripting language for my online game.. But then I realized that while the client wouldn''t have to run the slow Python much (most processing time goes to drawing), the server would then use Python almost solely. Meaning it could run maybe 1/5 or 1/10 the amount of players it could if it was pure C++ (assuming bandwidth isn''t limiting factor).

Now I''m not sure what to do: (1) Not use scripting at all, (2) try Python anyway and settle for it''s speed or (3) maybe write my own simplified scripting language that''s faster to interpret and more tailored for my needs. But considering I don''t have experience with the last one, it could (likely) end up being slower to interpret than Python...

Share this post


Link to post
Share on other sites
Ratman    181
It totally depends on your project. A scripting engine to do the cut scenes in pacman is a huge overkill; you''re going to go crazy without some form of scripting language to do an rpg. I know you want specific information, maybe if you posted a bit about your project or what you''re trying to do we could help a little better.

regards,
Ratman

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Scripting would benefit all applications except the smallest ones IMO. Say you have a simple text editor. But if anyone can write simple extra tools for it with Python, it''ll suddenly become incredibly flexible. Someone else could incorporate spell checking or, say, a regular expression search.

In games, well just look at Counterstrike and other successful mods based on Quake''s scripting capabilities.

Scripts may not allow you to work amazingly much faster, but they enable other people to safely extend your application without having access to source code. Or you could easily download new scripts from the net and start running them right away.

Share this post


Link to post
Share on other sites
Kylotan    10008
I am just talking generally. Some people claim that they can develop their game a lot more quickly using Python (eg. "I have felt so liberated by the speed with which I can make changes and see the effects, the speed with which I can put my ideas into practice and the flexibility of the code"), so I''d like to see some examples, more specifically to do with code than game design (ie. cutscenes, scripted behaviour). I''m not asking for help with my specific problem or project of my own, just some ideas of how it''s benefitting other people.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
granat    122
I would only use scripting if other people needed to add behavior to monsters without compiling or if I were thinking of making new levels for download containing new behavior without changing the exe file.

I don't think the development time is the reason for the use of scripting. Flexibility is the reason I think.

But what the Hell do I know ?

Let's here it from somebody who knows what they are talking about

[edited by - granat on March 16, 2003 12:27:14 PM]

Share this post


Link to post
Share on other sites
thehurricane    122
Okay, I think I see what you are looking for...concrete examples. I don't know how "right" my approach is, but maybe showing you a bit could help. In my 2D sidescroller almost all of my game classes are exposed to Lua with a slick automatic binding tool called ToLua. So then its possible to do things like this--say I want to have a new monster spawn when one monster is killed. Here's a snip of Lua code that defines what is executed when the monster dies:

--OnDeath Function-------------------
thisMonster.OnDeath =
function()
newMonster = Monster:new(thisMonster.X+20,thisMonster.Y)
newMonster.AI = AICollection.lizard2
newMonster.Sprite = SpriteCollection.lizardred
game.state.scene:AddObj(newMonster,true,true)
end
-------------------------------------

Basically I think whatever effort is put into implementing the scripting system more than pays off in the end; things are just easier to customize, and creating interesting events just kind of comes out of the functionality of the system. In a Pac-Man game, yeah--its overkill (probably but for the kind of interactivity that I want in my Metroid-style game going for Lua was a good choice, I think. Also remember you can implement a console in your game and make changes on the fly as the executable is running!

[edited by - thehurricane on March 16, 2003 12:28:51 PM]

Share this post


Link to post
Share on other sites
granat    122
quote:
Original post by thehurricane

--OnDeath Function-------------------
thisMonster.OnDeath =
function()
newMonster = Monster:new(thisMonster.X+20,thisMonster.Y)
newMonster.AI = AICollection.lizard2
newMonster.Sprite = SpriteCollection.lizardred
game.state.scene:AddObj(newMonster,true,true)
end
-------------------------------------




What you are doing here could have been done in the normal exe code and the code would look more like the rest of the code. Only if non-technical people need to create something or if you want to be able to expand the game later without recompiling does scripting have a use...right ? Or ?

My point is, don't spend time implementing scripts JUST because it sounds cool.





[edited by - granat on March 17, 2003 1:34:01 AM]

Share this post


Link to post
Share on other sites
Extrarius    1412
quote:
Original post by granat
[...]
What you are doing here could have been done in the normal exe code and the code would look more like the rest of the code. Only if non-technical people need to create something or if you want to be able to expand the game later without recompiling does scripting have a use...right ? Or ?

My point is, don't spend time implementing scripts JUST because it sounds cool.


Summary of the following:
Scripting is helpfull because of the flexability and locality it creates. It is also good because it allows for extensability which makes a game more enjoyable and gives it a longer life.

I agree that you don't always need a scripting language, but the flexibility is helpfull for most 'big' games. What if you just wanted any monster of type T to respawn on level 4 under condition C and T? Well, you could go into your game code and make an "int level" global, then in your T::Death() function add
if((level == 4) && C && D)
{
...
}
But if you decide to make monster type S respawn under condition E and F on level 6, you have to either duplicate the code, use more generic programming, or end up with some other kind of mess. You would probably duplicate the code, which isn't so bad, until you have 50 levels each with one monster type that respawns under certain conditions. With a scripting language, you can localize such conditions to the level itself, which means you have 20 lines of code that depend on the level stored inside the level itself instead of 1000 lines of code that depends on the level spread around your game engine (which will probably be harder to debug than a small script in each level since its spread over a lot of code rather than being localized).

'My game' is going to be an RTS, and I think scripting will greatly benefit it in several ways - It will be easy to create campaigns that depend on certain events for victory, in-game cinematics will be fairly easy to create, and it will be highly modable by any community that developes around the game (which almost always has the effect of prolonging the game's life and making it more enjoyable because you can take a break from the standard game without giving it up entirely).

[edited by - Extrarius on March 17, 2003 1:51:58 AM]

Share this post


Link to post
Share on other sites
CraZeE    217
i guess scripting not just come in for the designers. any part of an application that requires tqeaking multiple levels of variables could utilize scripting. i think this is most applicable in alpha/beta testing where, for instance, game balance is involved. instead of tweaking each units stats individually and recompiling, scripting can achieve it with the avoidance of time loss for compilation.

its true that natural language scripts are more applicable towards designers and artists whom are assumed to be less capable at handling cryptic codes. but the average scripting functionality can by all means be an equal counterpart of the actual language.
this means for programmers too, it would be interesting to just define a game engine to handle all events and rendering and etc. but every object placements and event routing is defined purely by scripts. imagine a script driven game... one engine can theoretically produce a huge number of games with little similarities in content!

Share this post


Link to post
Share on other sites
Shannon Barber    1681
A more pointed technical critism, for the particular example posted above, is that you are using script as a substitute for a data-driven design. You have more flexibility (thus complexity) than you actually need.

Until you start using control structures (for, while, etc...) scripting doesn''t buy you anything.

Most Quake mods are done using dll extentions. The bot AI is the only significant item that uses the scripts (and it''s ignored, because interpretted C is probably the last choice one would make for writing AI scripts).

Share this post


Link to post
Share on other sites
Sneftel    1788
MKH just hit on one of the big caveats of scripting: it's only useful where game content is procedural, and cannot be easily represented by data.

My adventure game engine is a good example of what does need scripting. Push the button on the wall? maybe it'd make a sound... maybe it'd make the robot walk three feet to the left... maybe it'd slip a fish in your ear IF the mail was on the drain and the bathrobe was on the hook and a few other items were in place, otherwise the fish would escape. (brownie points to the first guy to get the reference) The only efficient way to code that is to have a specific procedure for THAT BUTTON ONLY, which is where scripting comes into play.

Pacman? Quake? probably no scripting needed. Scripting is content in the form of instructions.

EDIT: oh, so an example from my game engine. This is just typed off the cuff, so there may be problems.

object {
name = button
DO_press = function(self, event)
if(currentroom.objects["mail"]) then
doevent(currentroom.objects["fish"], {verb="fly"})
end
end
}


How appropriate. You fight like a cow.

[edited by - sneftel on March 17, 2003 2:18:08 AM]

Share this post


Link to post
Share on other sites
Sneftel    1788
quote:
Original post by Wyrframe
Sneftel; two things. First, "You fight like a dairy farmer!".


Okay, so you get the other prize.
quote:
Secondly, I''m tempted to guess Starship Titanic (Fish in ear -> Babelfish, and Douglas Adams)

Oooh, so clooose. You got it with the babelfish, but the precise work with that sequence of actions?


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Kylotan    10008
All I''m really seeing then, is "scripts are good for your development team / modders" and "scripts can be good where a data-driven model would be too complex" perhaps. Nobody is finding using a higher level language to have a significant positive effect on the actual development of the main code then?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Flarelocke    410
Are we restricting ourselves to games here?

I personally would use Python to code a game in part or whole only if a) one of the primary features of the game is its customizability (such as one of those glorified engine demos like Quake, but probably for another genre, or perhaps something like Earth 2150''s customizable AI -- rather than inventing "EarthC", they could have simply integrated Python) or b) if it''s going to be a small, relatively simple game that would run at 1000 fps on my P4 (the threshold is probably around something like a SimCity or Civilization I game). In some cases, it won''t be as slow as you probably expect because rarely does someone think in C to use a hash map, whereas they''re the basic type of Python.

There are two niches adjacent to game programming in which Python is useful: self-educational purposes and content creation tools. As an example, I didn''t know a thing about how bezier curves worked. After reading some math on the subject, I coded a very simple program to allow me to play with bezier curves. I had a nice, flawless-but-simple program in two hours. It only took that long because I wasn''t familiar with functional language techniques at the time, nor was I familiar with the libraries I was using (libraries in Python are much easier to learn than libraries in C++, which all seem to use either very primitive types like char* (as opposed to std::string) or some type unique to the library -- Python''s types are very flexible and libraries all seem to be able to work with whatever types you give them. Also, never underestimate the use of introspection for this purpose. Typing code into IDLE to see what it does simply has no parallel in compiled languages for learning a library). I played with that program for a while. Three or four days later I came back to the program I had written and extended it to work with arbitrary chains of pairs vectors instead of simple points. It took half an hour.

Content creation tools like map makers or anything else unique to the game should probably be written in Python if you''ve got anyone who knows it. It''s just faster (to write, I mean) and easier to understand. (these things are part of game development too, you know) It might not be in your best interests to distribute code written in Python, though, because it''s easier to reverse engineer than assembly (or C, or any other native compiled language), even if you don''t include the source code.

Share this post


Link to post
Share on other sites
Extrarius    1412
quote:
Original post by Kylotan
All I''m really seeing then, is "scripts are good for your development team / modders" and "scripts can be good where a data-driven model would be too complex" perhaps. Nobody is finding using a higher level language to have a significant positive effect on the actual development of the main code then?[...]


If by "main code" you mean the "engine" (graphics, sound, input, etc), then you are correct. Scripting languages are usually used for game logic and not the processor intensive parts(the engine).

quote:
Original post by Magmai Kai Holmlor
[...]Most Quake mods are done using dll extentions. The bot AI is the only significant item that uses the scripts (and it''s ignored, because interpretted C is probably the last choice one would make for writing AI scripts).


Quake 1 had a scripting language called Quake C, (don''t remeber quake 2 modding), and Quake 3 has an X86 assembly VM (it might not get used, but it is there and the Mod SDK includes tools for compiling the mod code to it). Also, the Unreal engine uses scripting almost exclusively for all game logic. Many RTS games include some form of scripting for the single-player campaign, and almost all cRPG games use some form of scripting for much of the logic and data.

Half-Life used a DLL for modding, and I found it to be much more difficult than modding Quake 1. It has a fairly simple object hierarchy, but with all the single inheritence it isn''t easy to know what functions any object has available.
Since scripting languages are usually less complex(and higher level) than full languages, it is generally easier to figure out what code does and modify it.
Since a scripting langauge is usually interpreted, it isn''t too hard to build an editor into the game, which allows modifying the logic in realtime, which should decrease the time it takes to to fix logic errors since you can see the result almost instantly you know if its fixed, and if not you can change something and see the effect almost instantly again. If you hardcode the logic, it can take a long time to fix, especially if compile times get long. With compilation taking 1 minute, that means it will take at least 1 minute to test even the smallest of changes.
Also, as has been discussed in threads on Lisp, it often takes less lines of code to produce a given effect in a higher-leve language. Since there are less lines, there is a smaller area to search when a bug shows itself, and there is less are to make a mistake.

Yes, scripting is essentially just a more flexible form of data-driven design.

Share this post


Link to post
Share on other sites
Sneftel    1788
quote:
Original post by Kylotan
Nobody is finding using a higher level language to have a significant positive effect on the actual development of the main code then?



My codebase has many, many more lines of Lua than C++. That''s because it''s a game that is most crucially based on procedural content.

When using a scripting language for part of your program, it''s crucial that early on you build an exact dichotomy of what the job of the scripting system is. Failing to do that tends to cause rampant dilemmas of responsibility between modules, and an unnecessarily high amount of data transfer in and out of scripts (which is one major way to slow down most scripting languages). I''ve chosen to draw that line between algorithms and system calls, and game content. Basically, if it''s something that affects the STORY, it''s in Lua. The only exception to that rule are "helper scripts" that these scripts call.

I''ve seen a few games done completely in a scripting language (LISP is popular). But I think the killer app of scripting languages in the game development world is content.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Kylotan    10008
quote:
Original post by Extrarius
If by "main code" you mean the "engine" (graphics, sound, input, etc), then you are correct. Scripting languages are usually used for game logic and not the processor intensive parts(the engine).

95% of the ''engine'' is not processor intensive though. And I''m not necessarily looking at just gaming applications, since lessons learned elsewhere could be brought over to games.

quote:
Also, as has been discussed in threads on Lisp, it often takes less lines of code to produce a given effect in a higher-leve language. Since there are less lines, there is a smaller area to search when a bug shows itself, and there is less are to make a mistake.

I''d be interested to see examples of this being the case. About the only thing I can think of (from my experience of Python) is stuff like the list handling which make it easy to do one thing to a whole range of objects or values.

Maybe I should reword the question. Since I already know how scripting languages can be used in game development, I am mainly interested in seeing examples of where scripting language code (in a C/C++ engine) is significantly shorter than the equivalent C/C++ code in that same engine. I''m comparing the language syntax, libraries, and speed of development, but I''m not concerned about performance or compilation speed.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Extrarius    1412
I don't have an engine and a scripting language to find examples with, so I just flipped though my Lisp book looking for something that wouldn't be too difficult to implement in C++ as well, but everything that could be done in C++ would end up being about the same length. Most of the examples used symbols, cons lists, etc which you would have to recreate in C++ before you could code the same thing, so maybe the benefit of high-level languages is not that it takes less code but that they have more functionality built in. (Especially custom scripting languages, because you can create operators/functions/syntaxes/etc to fit your needs)
My primary reason for using a scripting language is for flexebility, and to be able to see changes instantly.

[edited by - Extrarius on March 17, 2003 3:28:22 PM]

Share this post


Link to post
Share on other sites
krelwyn    122
One thing to keep in mind when dealing with scripting languages, irregardless of the advantages of not having to deal with a compile-link-execute cycle, is that the language can be closely mapped to the problem domain. To me, that''s the single, most powerful argument to use a custom script language for a game.

Think about it, by the time you are ready to start adding the "real" game logic (anything that sits over the base engine level), you already have a firm idea of what the game needs to do. Design the script language to make that easy to accomplish.

One example that comes to mind (I remember reading about this, don''t have firsthand knowledge, so take with a grain of salt), is UnrealScript. The scripting language has the concept of "state", for which each entity can be in a certain state at any time, and there are language constructs which facilitate managing entity logic based upon it''s current state. Now there''s nothing there that can''t be (and hasn''t been) done already in C++, but the key point here is the language was designed in such a way to allow the programmers to implement game features faster than they could with native code.

It''s not much different than common business programming practice of putting data objects in a middle tier, so that business logic deals with objects, and doesn''t have to deal with SQL (or whatever the data store may be) -- Give yourself a tool to make writing the IMPORTANT parts of the program easier...

Share this post


Link to post
Share on other sites
bishop_pass    109
In the case of Lisp, one of the primary advantages, among many, is that you use Lisp to create a scripting language with your own semantics (it can be highly declaritive). The point is, Lisp provides the ability to create a new language (either simple or complex). Examples are STRIPS, PLANNER, CycL, etc.

Share this post


Link to post
Share on other sites