Scripts in Games?

Community Forums/Technical Discourse/Scripts in Games?

Yue(Posted May) [#1]
Why implement external scripting in a game? What benefits does an application have?


xlsior(Posted May) [#2]
External scripting allows external content without having to modify the game itself, e.g. extra levels, new functionality, user-created modifications, etc.

External scripting would allow others to modify the game to do things that the original creator never thought of, without him having to share the source code of the game itself.


Yue(Posted May) [#3]
Thanks You xisior.
Does this affect the performance of the executable?


degac(Posted May) [#4]
Usually the script is interpreted on a virtual machine (see LUA for example) and - of course - there's a little overhead doing this.
The script itself (generally) can't do too much thing directly, it will 'use' the main-game.
For example:

you have an entity walking in a room. You could 'attach' a script to an event (reaching a specific place in that room) to open a door.

the 'open the door' will be an external script that: ask to the game to 'move' the door, playing a sound, setting up some vars (door_opened=1) etc

the level of integration & complexity of the script is determinated by the game structure.

So basically you can program a 'game engine' (3d, lights, sounds, resource-management) and make everything externally via a script.


RemiD(Posted May) [#5]
You don't need LUA to write scripts for your game, a script can be structured as you want.
In a way a "ini file" or a "level file" that you can edit in a text file and that will modify the properties of the game/level is a script.

(I started programming by writing scripts for Morrowind, and what made me search for a better solution to create games was that it was too limited in what you can add/remove/modify (but the game is great nonetheless))


xlsior(Posted May) [#6]
Does this affect the performance of the executable?


Typically scripts are not compiled, and the code in a script will be slower than similar code compiled that's directly compiled as part of the executable -- but depending on the game supporting scripts will give you options that are otherwise not available, so as long as the scripts are fast enough to work smoothly, the speed penalty can still be worth it.


Kryzon(Posted May) [#7]
Typically scripts are not compiled, and the code in a script will be slower than similar code compiled that's directly compiled as part of the executable

This statement is true and I agree with it, but to avoid giving the wrong impression I want to add that a lot of major game engines, including some used by top studios, support interpreted scripts. Plenty of shipped games use scripting.

In absolute terms an interpreted script program is slower than a compiled program, but it's still absurdly fast and valid for writing your game logic with it.

The benefits of scripting while you're making your game is that you can quickly make modifications and click "reload" or similar to have the script update: you change it and see those changes played in real time.
This is very useful to adjust your game like you want it -- the speeds of things like animations, transitions, AI parameters and behaviour, adjusting the usabilty and interaction etc.


Yue(Posted May) [#8]
class MyClass 
{
   

  string numero;	


}
int  start()
{
		MyClass myClase;
		myClase.numero = "App";		

	

	xAppTitle ("hola");
	xGraphics3D(800, 600, 32, 0, 1);
	
		int camara = xCreateCamera(0);
		int sol = xCreateLight(0);
		int cubo = xCreateCube(0);

		xPositionEntity ( cubo, 0, 0, 10,0 );	
		
	while (!xKeyDown(1))
	{
		
		xUpdateWorld(1.0f);
		xTurnEntity (cubo, 1, 1, 1, 0);
		xRenderWorld(1.0f, 0 );
		xFlip();

	}

	
	return 0;
	
}




Thanks for the feedback. In this case, in the example above, you could put the graphics command and the title name of the application in the game. The rest would be someone could create a camera, a cube etc.

In such case, this is how people do the mods, for example in GTA games, I see a lot of files with values ​​that the user can modify.