Jade Empire Modding Wiki
Advertisement

The notion of working with scripts can be a daunting task, particularly if you have never done any programming.  This tutorial endeavors to explain some of the basics of working with scripts in Jade Empre, and to provide addtional resources for further assistance.

Understanding Script Structure[]

Learning about the basic syntax  - the rules that determine it's general structure - of a similar language such as C++ will allow you to understand the structure and logic of scripts.  Because of the scope of this topic there will likely be questions left unanswered by this tutorial.  It's content is not exhaustive by any means and it's intent is merely to help you get your foot in the door that is Jade Empire scripting.

That being said, here are some of the common features you will see while working with scripts in Jade Empire, with the most basic or pre-requisite information introduced first:

Statement:

string message = "This is a message";

An instruction for the script to do something.  Statements can involve variables, functions, decision-making structures, or loops.  Simple statements are terminated with a semi-colon (;) which marks the end of an instruction.  Multiple statements are typically written on seperate lines for readability.

Variables:

int nNumber = 5;

These hold data of a particular data type.  Variables have a format of [data type] [name] = [desired value];. Think of variables like a locker or a drawer in a filing cabinet which can only hold one item of a specific type.  The above code creates a variable named nNumber which contains the value 5.  This variable can only hold data classified as an int, which is short for integer. 

Variables in scripting languages are often preceeded with a lower case letter or series of letters to indicate the data type of the variable.  There are generally accepted conventions for basic data types, such as the use of the letter 'n' to indicate the variable contains an integer.  They cannot include spaces or certain special characters in the name.

Constants:

int TRUE = 1;

Similar to variables, the main difference being that constants are not intended to be changed once a value is given, hence the name.  While syntactically no different from a variable in the scripts, it is convention to only use upper case letters to name constants.  This way it is made clear that the value of the variable is not intended to be changed.

Comments:

// Georg Zoeller 25/06/2004

// - Added some new apl use actions

Comments are sections of code which are ignored by the compiler.  Their purpose is to provide additional information or documention to a script.  Comments are preceeded with two forward slashes (//).  Anything following these slashes on the same line does not have to conform to the syntax of the language. 

Functions:

void DestroyItem(object oOwner, int nItemType, int nCount) {
   //code the function carries out
}

Functions are sections of code that can be called to perform a certain task.  Somewhere in the script or the included scripts the function is defined.  This means that it is given a return type, a name, and a list of parameters required for it to do it's intended job.  The image above is an example of a function declaration.  This must be done before a function can be called (read as 'get the function to work').

The return type is the kind of data the function will return after it's finished executing its code.  In the above example the return type given in the declartion is void, meaning it does not return anything. 

The name is just that.  It's what's used to call the method.

The parameters list the pieces of information the function requires in order to run.  In this case the function is going to need an object, and 2 ints, in that order to work.

Functions are only good if you can call them.  Here is an example of the statement used to call the method declared above.

DestroyItem(object, itemType, count);

Notice that the data types for the method are not included, nor do the arguements (essentially the same thing as parameters) have the same names as in the definition.  When the function is called it expects the data provided to have the same types, in the same order, as in its definition.  It does not matter what the arguements have been named as long as they contain data of the same type and are passed in the correct order.

Pre-processor Directives:

#include "i_basics"

These are instructions handled before the code is compiled.  They are always preceeded by a hash tag (#).  You will often see these used at the top of scripts for include directives.  Include directives are used to effectively insert the contents of other scripts into the current one.  This is used to access things like variables and functions  that are defined in another script.

Decision-making structures and Loops[]

To be continued.

Advertisement