Introduction

CoreSE is a powerful, statically and strong typed, lightweight, embedded and a cross-platform, object-oriented scripting programming language written in C/C++, Client & Server side for Scripting Game Development and it was developed by Douglas Kitagawa. It is a class-based concurrent scripting language and it can be integrated with Lua or SQL.

CoreSE also contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators, control structures, and statements.

CoreSE supports procedural programming, object-oriented programming and functional programming. Thanks to special built-in methods, it can also be used as a prototype-based programming language.

CoreSE

CoreSE it is also very similar in some ways to C/C++ and Lua, but fundamentally different in some other aspects. The CoreSE language resembles C/C++ and Lua but does not have C/C++'s static typing and strong type checking and it is simple and flexible as Lua. CoreSE follows most of the C/C++ expression syntax, naming conventions and basic control-flow constructs which was the reason why it was named CoreSE (because it follows a different Course).

CoreSE has been developed from scratch for GRAVITY in order to offer an easy way to write high level code in a scripted language compatible with Lua and Delphi code for Windows platforms. It is written in C++ code that can be compiled on any platform using a C/C++ compiler.

Hello World

To get started with writing CoreSE, open your IDE or scratchpad and write your first Hello World! code using the following code:

OnPCLoginEvent: dialog "Hello World!";
Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.

Variable names can have normal alpha-numeric characters and can have numeric characters and it is case sensitive.

Understanding Alpha-Numeric Characters

When it comes to alphanumeric characters, the rule is that we can use letters including the characters from A to Z (which we call it adamantoise case also known as upper case) and the characters from a to z (moogle case also known as lower case).

How to name your variables

Here are the good practices on how to name your variables:

Understanding Numeric Characters

The rule is that we can use number digits from 0 to 9. Keep reading to understand the variable naming conventions for CoreSE.

A CoreSE identifier must start with a letter or underscore ( _ ); subsequent characters can also be digits (0-9). Because CoreSE is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).

Prefix Operator

In CoreSE Variables are dived into two types:


Prefix variables are used to define the scope and extent of a variable.

Postfix variables are used to define the type of the variable between integer (positive and negative integer numbers) or string.

Declaring Variables

To declare a variable in CoreSE first use the keyword var or set following by this choose your Prefix Operator plus the variable name and then use the comma (optional), i.e:

var $firstVariable; var $firstVariable set $firstVariable; set $firstVariable

To initialize your variables in CoreSE you must use the equal to ( = ) followed by the value of your variable, i.e:

set $firstVariable$ = "This is your first variable!";

You can also use a comma ( , ) instead of the equal to operator.

set $firstVariable$, "This is your first variable!";

The $ before the myVariable" word it's what we call it Variable Prefix.

For example,

set .@myVariable$ = "Text"; set .@myVariable$, "Text";

This syntax is used to declare global variables.

In this case the .@ are the Variable Prefixes.

You can also use this way to declare a local variable:

set $myVariable$ = "Text"; set $myVariable$, "Text";

By using the .@ symbols you will always declare a local variable.

Variable Scope

Let's suppose you declare a variable as follows:

set $variableName;

This is what we call it a global variable and it is called global because it is available to any other code in the current document.

Now let's change the example, let's suppose you are declaring a variable using:

set .@variableName;

This what we call local variable, because it is available only within that specific block of code. This is important for scripts which are called with no RID attached, that is, not triggered by a specific client object.

Global Prefix

Global variables are in fact properties of the global object. In CoreSE Script file the global object is the whole Server Side, so you can set and access global variables.

Consequently, you can access global variables declared from different Client Sides. For example, if a variable called $userName is declared in a Script, you can refer to this variable from the Server Side and Client Side.

They are stored by Zone Server in the database table mapreg.

How to declare a Global Variable

set $variableName;

Note: The $ before the variableName it is a global variable.

AI Prefix

They exist in the Client Side only and disappear when the Server Side restarts or when the script is reloaded.

Can be accessed from inside the Client Side or by calling the function getvariableofpc. Function objects can also have .variables which are accessible from inside the function, however getvariableofpc does NOT work on function objects.

How to declare an AI Variable

set .myVariable = 10; set .myVariable, 10; set .myVariable$ ="Text"; set .myVariable$,"Text";

Note: The . before the variableName it is an AI.


Global Prefix Constants

Global variables are in fact properties of the global object. In CoreSE script file the global object is the whole Server Side, so you can set and access global variables.

Consequently, you can access global variables declared from different Client Sides. For example, if a variable called $userName is declared in a Script, you can refer to this variable from the Server Side and Client Side.

A permanent global account variable stored by the Inter Server. They are stored in the global_acc_reg_num table and global_acc_reg_str.

set ##myVariable = 250; set ##myVariable, 250; set ##myVariable$ = "This is a string"; set ##myVariable$, "This is a string";
Local Prefix Constants

The Local Constants are stored by Inter Server in the acc_reg_num table and acc_reg_str.

A permanent global account variable stored by the Inter Server. They are stored in the "global_acc_reg_num" table and "global_acc_reg_str"

set #myVariable = 250; set #myVariable, 250; set #myVariable$ = "This is a string"; set #myVariable$, "This is a string";

The only difference you will note from normal # variables is when you have multiple Inter Servers connected to the same Zone Server. The # variables are unique to each Inter Server, while the ## variables are shared by all these Inter Servers.

Instance Prefix

These are used with the instancing system and are unique to each instance type. Can be accessed from inside the instance or by calling getinstancevar.

set 'myVariable = 250; set 'myVariable, 250; set 'myVariable$ = "This is a string"; set 'myVariable$, "This is a string";

Note: The # before the variableName it is a local constant variable.

Data Type Postfix

As previously stated in this documentation the Postfix is always used to define whether a variable is integer (positive, negative integer number. However whole numbers only) or string.

You can check all Postfix Data Types possibilities bellow:

Variable Scope Examples
Scope Data
varName Permanent Character Side integer variable
varName$ Permanent Character Zone string variable
@varName Temporary Character Zone integer variable
@varName$ Temporary Character Zone string variable
$varName$ Permanent Global string variable
$@varName Temporary Global integer variable
$@varName$ Temporary Global integer variable
.varName AI integer variable
.varName$ AI string variable
.@varName Local integer variable
.@varName$ Local integer variable
'varName Instance integer variable
'varName$ Instance string variable
#varName Permanent Local Account Zone integer variable
#varName$ Permanent Local Account Zone string variable
##varName Permanent Global Account Zone integer variable
##varName$ Permanent Global Account Zone string variable

You must always used the word set or var to define your variable, otherwise if a variable was never set, it is considered to equal zero for integer variables or an empty string ("", nothing between the quotes) for string variables or an empty string ("", nothing between the quotes) for string forever, and no trace remains of it even if it was stored with character or account data.

Array Data Type

There's not much to say about Array Data Type variables. These are variables capable to store multiple values in a single variable by using different indexes.

This data type will allow you to quickly fill up an array in one go.

Follow the pattern:

setarray {array name}[ {initial position} ] = value, value, value, ...; setarray {array name}[ {initial position} ], value, value, value, ...;

Here's a real world sample:

setarray .@myArray [0] = "Name", "Surname", "Last name", ...; setarray .@myArray[0], "Name", "Surname", "Last name", ...;
If and Else Statement

This is the basic conditional statement command, and just about the only one available in this scripting language. The condition can be any expression. All expressions resulting in a non-zero value will be considered True, including negative values. All expressions resulting in a zero are false.

If the expression results in True, the statement will be executed. If it isn't true, nothing happens and we move on to the next line of the script.


First Example

if (1) dialog "This will always print."; if (0) dialog "And this will never print."; if (5) dialog "This will also always print."; if (-1) dialog "Funny as it is, this will also print just fine.";

Second Example

.@answer = 1; input .@input; if (.@input == .@answer)   close;   dialog "Sorry, your answer is incorrect."; close;
Switch and Case Statement

The switch statement is similar to a series of if statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression the case statement(s) will to executed. The parser continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, the parser will go on executing the statements of the following case (fall-through).

Check the Example:

switch(select("Yes:No")) { case 1:   dialog "You said yes!";   break; case 2:   dialog "Aww, why?";   break; }
While Statement

This is probably the simplest and most frequently used loop structure. The 'while' statement can be interpreted as "while {condition} is true, perform {statement}".

It is a pretest loop, meaning the conditional expression is tested before any of the statements in the body of the loop are performed. If the condition evaluates to false, the statement(s) in the body of the loop is/are never executed. If the condition evaluates to true, the statement(s) are executed, then control transfers back to the conditional expression, which is reevaluated and the cycle continues.

Check the example below:

while (10 >= 1)) {   doThis; }
For Statement

Another pretest looping structure is the 'for' statement. It is considered a specialized form of the 'while' statement, and is usually associated with counter-controlled loops. Here are the steps of the 'for' statement: the initialize statement is executed first and only once. The condition test is performed. When the condition evaluates to false, the rest of the for statement is skipped. When the condition evaluates to true, the body of the loop is executed, then the update statement is executed (this usually involves incrementing a variable). Then the condition is reevaluated and the cycle continues.

First Example

for( <.@i = 1; .@i <= 5; .@i++ )   dialog "This line will print 5 times.";

Second Example

dialog "This will print the numbers 1 - 5."; for( .@i = 1; .@i <= 5; .@i++ )   dialog "Number: " + .@i;
Do Statement

The do...while is the only post-test loop structure available in this script language. With a post-test, the statements are executed once before the condition is tested. When the condition is true, the statement(s) are repeated. When the condition is false, control is transferred to the statement following the 'do...while' loop expression.

First Example

dialog "This will countdown from 10 to 1."; .@i = 10; do {   dialog .@i;   .@i -= 1; } while (.@i > 0);

Second Example

dialog "This menu will keep appearing until you pick Cancel"; do {   .@menu = select("One:Two:Three:Cancel"); } while (.@menu != 4);
Freeloop Statement

Toggling this to enabled (1) allows the script instance to bypass the infinite loop protection, allowing your script to loop as much as it may need. Disabling (0) will warn you if an infinite loop is detected.

The command will return the state of freeloop for the attached script, even if no argument is provided.

freeloop(1); // Enable script to loop freely // Be careful with what you do here for ( .@i = 0; .@i < .@bigloop; .@i++ ) {   doThis; // Will sleep the script for 1ms when detect an infinity loop to // Let AEGIS do what it needs to do (socket, timer, process, etc.) } freeloop(0); // Disable freeloop for ( .@i = 0; .@i < .@bigloop; .@i++ ) {   doThis; // Throw an infinity loop error }
Function Declarations
  1. Declare the function.
  2. Call the function anywhere within the script. It can also return a value when used with parentheses.
  3. Define the function within the script.
function script try {   doThat; } - script testing_function -1,{   .@try = is_function("It is a function"); // 1   .@not = is_function("Not a function"); // 0 }