what is scripting?

Started by
8 comments, last by Lonefox1 18 years, 2 months ago
can someone explaing to me scripting and the benefits and common tasks one would use scripting for in terms of game development (preferable something simple like pong or breakout) thanks.
Advertisement
SCripting is used to define the behaviour or set the rules of your game without having to recompile the whole application. Most scripting is text based and is fairly generic.

Your game would have a script engine that would read in the script at run time, parse it and set up the game environment.

Simple generic script.

WHEN <CONDITION> PERFORM <ACTION>

So in the case of Pong you could create the following script

WHEN <BALL intersects LEFTWALL> PERFORM { SOUND PONG; XVel = -XVel}

D.V.Carpe Diem
Scripting is typically when you embed another language into your game or application. Your game will then load small programs, or scripts, and execute them with the embedded language machine.

Scripts are useful as it lets the programmer get on with coding systems such as physics, rendering, etc whilst leaving the actual game logic to the game designers (or scripters). Scripting API are exposed by the programmer to the script language and are often a lot simpler than the C++ (or other) code that would normally perform the action. A script command such as "MoveEntity" could potentially translate into a lot more complex validation and updates in the game engine itself.

This could be accomplished using a wrapper API over the game engine, but it would still leave you the problem that a) designers would need to understand the language the engine is coded in and b) any changes to logic would mean the whole game module would need recompiling. Scripting languages are often much simpler for non-programmers to pick up (Lua, GameMonkey, Python) and because they're loaded, compiled and run at runtime, it means that your actual game engine can remain the same with any logic changes being made within script.

I hope this answers your question?!
In terms of pong and breakout... You'd create your game 'engine' which is capable of creating sprites and drawing them, it can load and play sounds and do all other actions you'd expect a game to do. However, if you were scripting it you wouldn't have any mention anywhere about the pong or breakout terminology. Instead you'd program scripts for your games to capture the logic and tell the sprites where to be drawn and what to do when they collide.

Bear in mind though that there are also different levels of scripting. Some games, such as Half-Life used scripting to say "if player is here, play this cutscene or awaken this enemy". The core game logic would still be in C++ code, just special events are scripted. However with the likes of Unreal, more and more is scripted in the game meaning that the core engine doesn't really have much to do with game logic at all, instead it just obeys what the scripts tell it to do.

If you're interested, look at my gmSDL 0.1 preview which is simply an executable that contains bindings for SDL to GameMonkey Script. The script itself handles the movement and creation of sprites, SDL just displays them. I will shortly release pong, pacman and probably breakout coded in nothing but script with this binding. Pacman is almost complete now.
hey guys, thanks for the replies.

so scripting performs the game logic and sets up the environment? basically like what one would call a configuration file for the game environment, and the ability to modify the game logic without having to recompile all the files?


hmmm



oic, scripting enables a developer to control the aspects of the game at a much higher level of design.

so if i am creating a breakout game, when the ball hits a blocks, i can have a script to say "when block and ball collide, play block destruction animation" etc...


so basically that script would somehow link directly to c++ function call? or have an alias of somesort?

for example if i have a function in c++ called

playAnimation(animation x)
{
select animation x from animation database
}
---------
in a script, i can call that c++ function to play whatever animation script i want at what action performed?

---------------------------------


hmmm.


Quote:Original post by evolutional
In terms of pong and breakout... You'd create your game 'engine' which is capable of creating sprites and drawing them, it can load and play sounds and do all other actions you'd expect a game to do. However, if you were scripting it you wouldn't have any mention anywhere about the pong or breakout terminology. Instead you'd program scripts for your games to capture the logic and tell the sprites where to be drawn and what to do when they collide.

Bear in mind though that there are also different levels of scripting. Some games, such as Half-Life used scripting to say "if player is here, play this cutscene or awaken this enemy". The core game logic would still be in C++ code, just special events are scripted. However with the likes of Unreal, more and more is scripted in the game meaning that the core engine doesn't really have much to do with game logic at all, instead it just obeys what the scripts tell it to do.

If you're interested, look at my gmSDL 0.1 preview which is simply an executable that contains bindings for SDL to GameMonkey Script. The script itself handles the movement and creation of sprites, SDL just displays them. I will shortly release pong, pacman and probably breakout coded in nothing but script with this binding. Pacman is almost complete now.


Quote:Original post by baker
oic, scripting enables a developer to control the aspects of the game at a much higher level of design.


Yeap, that's right.

Quote:
so if i am creating a breakout game, when the ball hits a blocks, i can have a script to say "when block and ball collide, play block destruction animation" etc...

so basically that script would somehow link directly to c++ function call? or have an alias of somesort?
in a script, i can call that c++ function to play whatever animation script i want at what action performed?


Pretty much. It can be as simple or as complicated as you want. In your example, your C++ function would:-

- retreive the animation from the database
- check that it can be played on this object
- assign an instance of the animation to the object
- tell the animation manager to play it

But in script, you could just call:- PlayAnimation( object, anim );

Another example would be motion. If you wanted an entity to move to a map location, the engine code would do the following:-

- retreive the location details
- update the location if the selected is impassable
- plot a path from current location to the new location
- update the entity on each frame to ensure that they're moving towards the object
- test that nothing gets in their way (if so, reevaluate path)

The script command could just be a simple:- Object.MoveTo( place );

Some scripting languages like Lua and GameMonkey allow you to create virtual 'threads' in the machine that make operations like this really simple.
awesome, it seems the idea of scripting is getting clearer.

a few yrs ago, i wrote a simple game of pong in java. basically i just put all the game logic, collision detection, error checks, etc... in the main loop of the program.

so if i were to script it, most of all whats in the main processing would be in the script.


cool, thanks for the explanation evolution.

i looked through your code and it seems your technical abilities are awesome!
World of Warcraft is an excellent example of the use of LUA script in a commercial game - the user interface is set up by scripts, and so the entire thing can be edited and changed to suite an individual players style, without changing the underlying game.

The quake series of games are an extreme, where the whole thing is basically scripted, which is how people make mods, and even the physics is handled in script. The script is basicaly C++ ;)

For myself, I use scripts for all things configurable. Key bindings are in a script so that it can contain lines like:
if (class == scout)   Bind("x", thrust);else   Bind("x", fire);

And my world is procedural, and the procedure is a script, so that rather than people making new maps which I load from a map file, they write new scripts which I execute.
ive always dodged learning about scripts till i read this post cause i didnt have a clue what one was. all becomes clear! good job!

This topic is closed to new replies.

Advertisement