Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why use scripting in games?

Started by wannabean333 Jun 29, 2004 at 7:00 PM 48 replies 11k views
Original Post
wannabean333
wannabean333
hey everyone- I'm making key decisions in the planning of my game right now, one of them is to continue spending time on planning the dynamics of my game into either a scripting engine or hard-coding. Why use scripting in a game? Unless they would change often after the installation of the game (which they most likely will not), why would I need to spend endless hours debugging a whole new programming language? I understand scripting would be good for mods and things like that, but I doubt my engine will be remotely good enough for someone to spend time modifying it. Maybe levels and things like that, but those will be external no matter what and not even "scripting". Should I bother making a scripting engine? Aside from storing cinematic and special effect scripting (just referencing to built in functions), is there anything else worth scripting?
Raduprv
Raduprv
Usually you don't have to make a scripting engine. You just embed a scripting language in your engine, and make some wrapper functions.
A scriptig is good if you want to allow your users to make mods. If you don't plan to do that, then it's not really usefull.
Sneftel
Sneftel
There's some games which don't really need scripting. Generally, if you need lots of one-off behaviors, that's an ideal scripting situation. For example, an adventure game where some particular switch causes a box to fall out of the sky if and only if the player has a rope.

Understand: a scripting language is for you, not for other people. It allows you to write levels and characters and other objects in a more natural representation than they would be in C++ or flat data files. (of course, if you're not the one that'll be designing the levels, replace "you" with "level designers"). If you feel that the game's operation is suitably simple and normalized that representing the game purely as data is possible, by all means forgo the scripting.
Stan100
Stan100
Scripting is good for lots of things. What genre is your game? (RPG, Strategy, etc)

Assuming your game is an RPG, lets say you want the map to get fuzzy when the main character gets to point (5,10)

In code you might do something like this: (psuedo/C++)

if ( (Main.x==5) && (Main.y==10) ){//stuff}


That would be a lot of hard coding for special events. Scripts allow lots of information to be held externally, and you don't have to recompile everytime. I know you said besides special effects. That's where I'll go next.

Character interaction and NPC placement/control: Just like detection for special effects, when a character enters an area, things can happen. Mostly trigger-like events. But you can also have your system set up so you can create NPC objects in the script, to be maintained in the script.

Another reason is if you have a team to work with. You may have people who are very imaginative, and that you trust cuold put together a good enough timeline. They may not know how to code. Well, save yourself some effort and put them to work! :) Seriously, if you put together a high end script langauge, they can do it, and besides, since it doesn't need to be recompiled, they can test it without bugging the coders.

To Sum It Up:

Scripts are great because you can use them for whatever purpose you want. There is no "script language", just common guidlines. And even those can be passed. Scripts were made because they allow for creator-defined events to occur on cue. They are whatever you want them to be, just don't overcomplicate it.

I hope I helped. :)
-----If you thought I was helpful, rate me down.If you thought I wasn't helpful, rate me down as well.This idiot didn't read my signature and tried to insult me.
graveyard filla
graveyard filla
im a little confused now...

you guys are all acting like scripting is useless unless you want other people to modify the game.

im working on a 2D RPG w / C++, and have a decent amount of the bare engine done. i can now make as many maps as i want, and the player can walk around the maps. so basically, i can make an entire world that the player can walk around in.

now i just need to add content. i was under the impression, that i should learn a scripting language like Python, and embed it into my game. IE, all game content should be coded in Python. NPC interaction, character dialogue, world interaction (IE going on missions and such), ETC.

since no one else will be working on the game but me, should i still go with a scripting language? or should i just use text files to store data and then parse the data with my C++ engine for thigns like character dialogue, world interaction, ETC, basically all the games content?

thanks for any help!!!
FTA, my 2D futuristic action MMORPG
paradoxnj
paradoxnj
Scripting is useful because it allows you to make changes to parts of a game without having to recompile the entire game. If you want to change the way an enemy character behaves, you change the script and just restart the game. No need to recompile the code. That's the main advantage.
wannabean333
wannabean333
if the only advantages are no need to recompile and mod-ability, it seems like a waste of time for me.

for my engine.

Thanks for the input.
Renze
Renze
How are we defining 'script'?

If a script is just a file or something that the main program reads and uses for the primary function of the program, I'd say scripting is crucial.

Everything either scripted or hard-coded...? Is that an over-simplified explanation?
------------------------------NE1 HAV LABIS CAMON FRO TRD??
_the_phantom_
_the_phantom_
Quote:
Original post by graveyard filla
im a little confused now...

you guys are all acting like scripting is useless unless you want other people to modify the game.


nope, scripting is usefull whenever you want to reduce hardcoding in a game or program so that you can change values and behaviours without having to rebuild everything and restart the program.

For example, you're working on a RPG, lets say you've got a wizard who you want to act a certain way with a character but then later decide you want him to act differently.
Now, without scripting you'd have to change the C++ code, change all the code around, recompile and restart.
With a script you'd change the script file and restart.
dont like it still? go back and fiddle abit.

If you get really clever you could infact have a small script editor built right into the game, allowing you to reprogram characters on the fly without even having to leave the game its self.
If you've got a console you could even allow yourself to use script code directly in it to modifiy parts of the game, say give yourself a big sword for testing reasons.

Frankly, the posibilties are endless when you start thinking about it [smile]
_the_phantom_
_the_phantom_
Quote:
Original post by wannabean333
if the only advantages are no need to recompile and mod-ability, it seems like a waste of time for me.

for my engine.


It all depends on the size and scope of what you plan on doing.
Once you get alot of code involving templates and other things and you find yourself sitting through huge build times just to change one little thing you'll wish you had gone with scripting just to make your life easier.

With scripting you've everything to gain and nowt to lose, you gain flexibilty at the expense of a small amount of CPU time and your time is more valuable than that any day [smile]

Scrpting is great, see above for a couple of reasons why, and if you plan on a project of a reasonable size you'll be better of with it than without it imo [smile]
Raduprv
Raduprv
The non compilation thing is a DISSADVANTAGE!
Basically, any decent C IDE will compile only the files that were changed. Most of the scripting language compilers, on the other hand, don't have this functionality, so you have to compile ALL the scripting code every time you want to change something, no matter how small. This really sucks, especially if the scripting component is really big.
_the_phantom_
_the_phantom_
you compile you're scripts? for testing? [wow]
Are we talking run time compile or compile time compile?
Raduprv
Raduprv
Compile time compile, of course. I am not masochist enough to wait 1 minute each time I start my server.
Do you know a better way to load test my scripts without compiling? ^.^
Feral
Feral
Quote:
Original post by Sneftel
...
Understand: a scripting language is for you, not for other people. ...


/me eye's slide to a stop.

I have to disagree. The major reason for a scripting language is for other people. People such as the level designers you mentioned, the moders and so on.

Why is Morrowind still going strong in the user community? Same with Neverwinter nights? .. because the mod community can do something with the programs.

About the only use for a script language for me for my game is ease of configuration file parsing. For my end user.. they can configure the game to their liking (though most such options should have a GUI front end, but I digress.) and extend the game (new models and such like).

As I see it 9 times out of 10 it is easier to do whatever you want to do directly in code, scripting is for the end user, or the level designers and other developer side content creation folks. To agree with thoughts above, when you want to separate game(content) from engine. A nice thing about working with scripts is the lack of dev side compilation. Fwiw, with the example rpg wizard above if you wanted to avoid scripting throw the code related to him in a DLL or the like perhaps..

As an aside I tend to think making a new script language just for your game might be overkill, consider Lua or the dozen other existing script languages perhaps?
_the_phantom_
_the_phantom_
Quote:
Original post by Raduprv
Compile time compile, of course. I am not masochist enough to wait 1 minute each time I start my server.
Do you know a better way to load test my scripts without compiling? ^.^


Well, if compiling them really is taking that long i'd and you cant deal with waiting for them to compile on server startup I'd probably write a small tool to compile or not compile a script based on its changed date vs the changed date of its compiled version, however as to if thats possible would depend on what you are using for scripting, how you build the script files and other things, it would probably work well for say using Lua as a scripting system as all the compiled files are independant of each other anyways.
Nemesis2k2
Nemesis2k2
There's an alternative that has a lot of the advantages of scripting, but not as many disadvantages (and best of all, it takes virtually no time to implement). Basically, make your "scripts" functions in a DLL. Load them dynamically, and make a uniform interface you can use (a message system works well for this).

I'll be using this system for my engine. It's got a lot of things up on a scripting system, namely:
-You don't have to write a compiler or a VM (thank god)
-The scripts are 100% machine code, and can be optimised much better than any compiler you'd write or find open source chances are.
-You can code in C++ rather than another language (Personally, I prefer this. I don't see how having to learn/make another language helps me develop the game. Most of the dirty work will be taken care of by provided functions anyway.)

There are a few disadvantages, which are:
-Less secure. People can put in whatever code they choose. (I don't think this is a biggie. People download executables all the time. You expect that someone isn't going to put something malicious in something like this.)
-Harder to debug during development


And that's about it as far as I can see. Personally, I think the DLL solution would work better for most games than a full blown scripting system.
Raduprv
Raduprv
Quote:
Original post by _the_phantom_
Well, if compiling them really is taking that long i'd and you cant deal with waiting for them to compile on server startup I'd probably write a small tool to compile or not compile a script based on its changed date vs the changed date of its compiled version, however as to if thats possible would depend on what you are using for scripting, how you build the script files and other things, it would probably work well for say using Lua as a scripting system as all the compiled files are independant of each other anyways.


I am using Small, not LUA. And all the scripts are compiled in one single file (I don't want to have different virtual machines for each script).
Feral
Feral
Quote:
Original post by Nemesis2k2
...And that's about it as far as I can see. Personally, I think the DLL solution would work better for most games than a full blown scripting system.


Busy thread :)

A DLL based script system only works when you have code literate content creation folks. This I think is the largest problem with this strategy. Compile time could also be a factor for a large program, I’d think.

Still, it is nice to DL a nwn module and know it can't format my HD... I do doubt most users have a clue nor care about such things though as most modules and other such mods are often acquired from reputable DL sites...
_the_phantom_
_the_phantom_
Quote:
Original post by Nemesis2k2
-You don't have to write a compiler or a VM (thank god)

Embed Lua. Job done.
Quote:

-The scripts are 100% machine code, and can be optimised much better than any compiler you'd write or find open source chances are.

Shouldnt be using scripting for time critical sections of games anyways so this isnt that important.
Quote:

-You can code in C++ rather than another language (Personally, I prefer this. I don't see how having to learn/make another language helps me develop the game. Most of the dirty work will be taken care of by provided functions anyway.)

Something like Lua can be learnt in an hour or so, its very light weight and frankly, if you've learnt C++ it would be a breeze to learn. You still access your provided functions, just via the script instead of hardcoding.

Quote:

-Harder to debug during development

This is potentialy a biggy.
You can also add
- Harder to make changes on the fly and keep them persistant (see my inbuilt script editor above)
- Harder for others to expand (not so important in a one man team i guess, but if you ever get a mapper who want to mix fucntionality X and Y in a game it will be much easier for him to work with something simple like Lua and cut and paste the code then for him to explain to you what the want and for you to go away and hardcode it and debug it)
- probably others but i'm getting too tired to think atm [wink]
Quote:

And that's about it as far as I can see. Personally, I think the DLL solution would work better for most games than a full blown scripting system.


It totaly depends on the scope of the game and if you plan on making it extenable in any way then scripting is a much better direction to head in than a hardcoded system.
For example, when making a HL mod there were times i wished things were scripted so that I could quickly make a change to some code and distrube the changes to the testers to get on with things while they were still about instead of having to load VC++, fiddle, compile, test locally, distrube, wait for ppl to download, upload changes, compile linux code, update server, restart server, [fix crashes in linux code for god knows what reason], get everyone back on, play test, repeat until everyone gets bored of waiting for updates and goes away.

End of the day, its upto you, I didnt see the value in scripts myself until I looked into them a bit more, saw how flexible they were and took a bit of time to learn to intergrate the use them.

My first test was a work project, scripting is used to dynamically allocate off objects in the main code based on a gameid and passed it in data needed to parse the data retrived from said server. Could have hardcoded it but the old system was like that and it was a pain to update and change and intergrate new games properly. Could have put everything in a data file but it wasnt as easy (i'd have to parse the data file, setup internal tables, setup function pointers, deal with all kinds of mappings), instead a script with a bunch of game id tokens and a function which is basical alot of 'if' statements and a fucntion call back to C++ and the job was done. Easy for me to maintain. Easy for others to maintain and pretty easy for another program to generate based on a database (which never happened, slight case of losing job).
_the_phantom_
_the_phantom_
Quote:
Original post by Raduprv
I am using Small, not LUA. And all the scripts are compiled in one single file (I don't want to have different virtual machines for each script).


Hmm well that probably knocks my idea on the head then, and i dont know owt about Small to help further [smile], thought i would say it was more a of limit of the scripting system than scripting in general which are causing you the problems [wink]

btw, you dont need to have a virtual machine per script with Lua, just load the scripts into the same VM and its all done [smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.