Skip to end of metadata
Go to start of metadata

Function Declaration

In World at War, functions could be written simply by writing the name of the function followed by any parameters you wish the function to have. In Black Ops 3, you simply need to add the "function" keyword before every function declaration you make: 

 

//WaW
testfunction(parameter)
{
	some code()
} 
 
//BO3
function testfunction(parameter)
{
	some code()
} 

Function Parameters

Function parameters have had a small boost in ability since WaW. The main change to function parameters is that you are now able to set a parameter default. That looks like this:

function testingFunction( myPram = false )
{
}

The above code shows that if you where to call upon the variable "myPram" within the "testingFunction" without having declared what myPram is within the function call then it would fall back to its parameter default, of which in this instance is "false".

Function Scopes

Now that Namespaces are open to us, we've also been given acces to function scopes. If you don't know what a function scope is then: A function can have a specific scope. Let's say we made a function with a private scope. this would mean we would only be able to use that function within our current .gsc file. If you have a global scope function the you would be able to call it externally ( from another .gsc file ).

function private testingFunction( ) // this indicates that it is a private scope function 
function testingFunction( )         // this indicates that its a public scope function

Function Duplication

As well as being given function scopes with namespaces. We've also now got a way to declare duplicate function names. This means in one namespace we can have a function called "init()" and then in a different namespace we could have the same function name ( "init()" ) because of the namespaces these functions will not confict. Here's an example to better show the system off:

// zm_file_one.gsc
#namespace zm_file_one			// Define our name space
function init() {				// Declare our function init()
	iPrintLn("Testing");
} 
 
// zm_file_two.gsc
#using zm_file_one;
function init() {				// Declare init() again in a different file.
	iPrintLn("Testing two");
	zm_file_one::init(); 		// See how I am able to use the same function name because its attached to a different name space
}

 

Namespaces

You can include an external script into your current script by doing:

#using scripts\zm\zm_usermap;

 

You can then call any function from that script by using the filename as a prefix:

zm_usermap::some_func();

 

Calling External Functions

<WIP>

Storing Functions in a Variable (pointers)

function testfunction(parameter)
{
	myFunc = &some_func;
} 
 
some_func()
{
 
}

 

Flags

flag_init(), flag_set, flag(), and flag_clear have been moved to flag_shared

#using scripts\shared\flag_shared;
 
function testfunction(parameter)
{
	//WaW: flag_init("flag");
	level flag::init("flag");
 
	//WaW: if(flag("flag"))
	if(level flag::get("flag"))
 
	//WaW: flag_set("flag");
	level flag::set("flag");
 
	//WaW: flag_clear("flag");
	level flag::clear("flag");
} 

 

GetStruct() and GetStructArray()

#using scripts\codescripts\struct;

function testfunction(parameter)
{
	//WaW:  struct = getStruct("something", "targetname");
	struct = struct::get("something", "targetname");

	//WaW:  structs = getStructArray("something", "targetname");
	structs = struct::get_array("something", "targetname");
} 

 

Weapon System (Giving, Getting, Switching, etc)

BO3 now treats weapons as entities instead of just strings. In order to do any weapon operations, you must first initialize a weapon variable from the string name:

function testfunction(parameter)
{
	string = "smg_standard";
	weapon = getWeapon(string); //initialize the weapon
	self giveWeapon(weapon); //giving an entity instead of just a string now.
	self GiveMaxAmmo(weapon);
	self SwitchToWeapon(weapon);
}


Weapon Stats are now stored as fields of the weapon entitiy instead of obtained from engine functions:

function testfunction(parameter)
{
	string = "smg_standard";
	weapon = getWeapon(string);
	displayName = weapon.displayName;
	ammo = weapon.ammo;
}

GetWorldModel()

function testfunction(parameter)
{
	string = "smg_standard";
	//WaW: model = GetWorldModel(string);
	model = GetWeaponWorldModel(getWeapon(string)); //Must pass an initialized weapon entity and also note the function for getting the model has been renamed.
}

The Callbacks System

A much more elegant way of getting your scripts threaded into the level at the right time (preload, post load, post load with specific requirements). You can see a full explanation of this feature on the dedicated page: BO3 | Callbacks System

enable_trigger() & disable_trigger()

These functions have been replaced with:

trigger TriggerEnable(<bool>);

where passing true will enable the trigger and false will disable it.