Contents Up Previous Next

Extender functions

Suppose that you wanted to add a new function, "Scream", to characters which would make them cry out "AARRRGGGHHH". Because the Character type is defined within AGS, it's not possible for you to just add a method to it.

That's where Extender Functions come in. Here's an example:

function Scream(this Character*)
{
this.Say("AAAAARRRRGGGGHHHHHH!!!!");
}
This adds a new "Scream" function to the Character type, so that in your script code elsewhere you can do things like:
player.Scream();
character[EGO].Scream();
and so on.

Where do I put this code?

In the script header, you'd put:

import function Scream(this Character*);

and then put the main function in the script file. This will then allow it to be used by other scripts.