VoidExpanse/scripting api: Difference between revisions

From AtomicTorchWiki
No edit summary
 
(15 intermediate revisions by 5 users not shown)
Line 2: Line 2:


== Basic concepts ==
== Basic concepts ==
Scripting is done via actions that custom scripts can subscribe to. There are number of actions that are called by server automatically, plus users can create their own actions and call them when needed. This also makes possible for users to create scripting frameworks for others to use.
Scripting is done via actions that custom scripts can subscribe to. There are a number of actions that are called by servers automatically, plus users can create their own actions and call them when needed. This also makes it possible for users to create scripting frameworks/libraries for others to use.
Each action has one argument (ΓÇ£argsΓÇ¥) that is a JavaScript object containing several variables inside depending on a particular action. In some actions this ΓÇ£argsΓÇ¥ object can be empty. But either way it allows for unified format for all actions within the scripting system.
Each action has one argument (ΓÇ£argsΓÇ¥) that is a JavaScript object containing several properties depending on which action is being called. In some actions this ΓÇ£argsΓÇ¥ object can be empty. But either way, it allows for a unified format for all actions within the scripting system.


=== Scripting naming convention ===
=== Scripting naming convention ===
* String IDΓÇÖs in mods can only contain alphanumeric characters and underscores. Any other characters are illegal.
* String IDΓÇÖs in mods can only contain alphanumeric characters and underscores. Any other characters are illegal.
* Using underscore for variables and properties.
* Use underscore for variables and properties.
* Using CamelCase for functions and methods.
* Use CamelCase for functions and methods.
* zxc_q - ΓÇ£qΓÇ¥ in the variable always represents ΓÇ£quantityΓÇ¥ or ΓÇ£number of ...ΓÇ¥.
* zxc_q - ΓÇ£qΓÇ¥ in the variable always represents ΓÇ£quantityΓÇ¥ or ΓÇ£number of ...ΓÇ¥.
* zxc_id - ΓÇ£idΓÇ¥ always means either string id from XML file if it is of the type of string, or if it is uint then it is entity (instance) id of some object.
* zxc_id - ΓÇ£idΓÇ¥ always means either a string id from a XML file if it is of the type of string, or if it is a uint then it is an entity (instance) id of some object.
* zxc_req - ΓÇ£reqΓÇ¥ always means ΓÇ£requirementsΓÇ¥.
* zxc_req - ΓÇ£reqΓÇ¥ always means ΓÇ£requirementsΓÇ¥.
* All mods should prefix their variables, functions, classes, storage keys and all the rest with a key for isolation from other mods, example of such prefix would be ΓÇ£prf_ΓÇ¥ -> ΓÇ£prf_some_variableΓÇ¥, ΓÇ£prf_SomeFunctionΓÇ¥.
* All mods should prefix their variables, functions, classes, storage keys, etc with a key for isolation from other mods. An example of such a prefix would be ΓÇ£prf_ΓÇ¥ -> ΓÇ£prf_some_variableΓÇ¥, ΓÇ£prf_SomeFunctionΓÇ¥.


=== Internal scripts (Overridable) ===
=== Internal scripts (Overridable) ===
These scripts are called usually once and only in a particular situation. Each of these script files must exist in only one instance. If a new script is added the previous one will be overridden. Each of the script files must implement only one script action. Usually players should not modify these scripts unless they want to completely re-implement some game feature.
{{Main|VoidExpanse/Internal_scripts|Internal scripts}}
These scripts are usually only called once and only in a particular situation. Each of these script files must exist in only one instance. If a new script is added the previous one will be overridden. Each of the script files must implement only one script action. Usually players should not modify these scripts unless they want to completely re-implement some game feature.


=== Global scripts (called in the world dynamically) ===
=== Global scripts (called in the world dynamically) ===
{{Main|VoidExpanse/Global_scripts|Global scripts}}
Global scripts are executed continuously during gameplay. For each event there could be many bound scripts. Also it is possible to create custom actions and subscribe to them.
Global scripts are executed continuously during gameplay. For each event there could be many bound scripts. Also it is possible to create custom actions and subscribe to them.
Please note: OnInit() method is executed only for Global and Internal scripts.


=== Object scripts ===
{{Main|VoidExpanse/Object_scripts|Object scripts}}
Object scripts are scripts attached to a particular game object. When that object starts an action, if a script has an appropriate handler for this action it will be executed.


=== Object scripts ===
=== Events ===
Object scripts are scripts attached to a particular game object. When that object starts an action, if script has an appropriate handler for this action it will be executed.
[[VoidExpanse/events|List of Events]]




Line 28: Line 34:


=== Library inclusion and scopes usage ===
=== Library inclusion and scopes usage ===
Preprocessor directive <code>include(libname.js)</code> includes a library scripts into a current JS instance. Library scripts also can include each other (no echo effect will appear).
Preprocessor directive <code>include(libname.js);</code> includes a library script into the current JS instance. Library scripts can also include other libraries (no echo effect will appear).


Allows to use functions and objects of these libraries in this particular script instance.
Allows modders to use functions and objects of these libraries in this particular script instance.
* Inclusions of libraries directive must be the first lines in the script file (not necessarily, but preferably - to maintain order in scripts).
* Include directive must be the first lines in the script file (not necessarily, but preferably - to maintain order in scripts).
* All include directives must be before first function declaration.
* All include directives must be before the first function declaration in the file.


Preprocessor directive <code>using(scopename)</code> allows to use specific scope in a specific script. Scope name must be an existing scope name (see scopes below). Except for some specific scopes (like topic or npc), which are available only in specific places, like topic scripts or AI behaviors.
Preprocessor directive <code>using(scopename);</code> allows modders to use a specific scope in a specific script. Scope name must be an existing scope name (see scopes below). Except for some specific scopes (like topic or npc), which are available only in specific places, like topic scripts or AI behaviors.


=== Scopes ===
=== Scopes ===
Line 40: Line 46:


* [[VoidExpanse/scope-config]] (available: global)
* [[VoidExpanse/scope-config]] (available: global)
* [[VoidExpanse/scope-script]] (available: ???)
* [[VoidExpanse/scope-script]] (available: global)
* [[VoidExpanse/scope-actions]] (available: ???)
* [[VoidExpanse/scope-actions]] (available: global)
* [[VoidExpanse/scope-server]] (available: ???)
* [[VoidExpanse/scope-items]] (available: global)
* [[VoidExpanse/scope-generator]] (available: ???)
* [[VoidExpanse/scope-server]] (available: global)
* [[VoidExpanse/scope-spawn]] (available: ???)
* [[VoidExpanse/scope-generator]] (available: global)
* [[VoidExpanse/scope-station]] (available: ???)
* [[VoidExpanse/scope-spawn]] (available: global)
* [[VoidExpanse/scope-chat]] (available: ???)
* [[VoidExpanse/scope-station]] (available: global)
* [[VoidExpanse/scope-console]] (available: ???)
* [[VoidExpanse/scope-chat]] (available: global)
* [[VoidExpanse/scope-storage]] (available: ???)
* [[VoidExpanse/scope-console]] (available: global)
* [[VoidExpanse/scope-game]] (available: ???)
* [[VoidExpanse/scope-storage]] (available: global)
* [[VoidExpanse/scope-ship]] (available: ???)
* [[VoidExpanse/scope-game]] (available: global)
* [[VoidExpanse/scope-visual]] (available: ???)
* [[VoidExpanse/scope-ship]] (available: global)
* [[VoidExpanse/scope-player]] (available: ???)
* [[VoidExpanse/scope-visual]] (available: global)
* [[VoidExpanse/scope-topic]] (available: ???)
* [[VoidExpanse/scope-player]] (available: global)
* [[VoidExpanse/scope-relations]] (available: ???)
* [[VoidExpanse/scope-topic]] (available: only in topics)
* [[VoidExpanse/scope-xxx]] (available: ???)
* [[VoidExpanse/scope-topics]] (available: global)
* [[VoidExpanse/scope-relations]] (available: global)
* [[VoidExpanse/scope-npc]] (available: global)
* [[VoidExpanse/scope-timer]] (available: global)
* [[VoidExpanse/scope-debug]] (available: global)
 
== Device scripts ==
{{Main|VoidExpanse/Device_scripts|Device scripts}}
Devices uses effect scripts, which is similar to any object scripts, but uses itΓÇÖs own special system of arguments. These scripts are shared between instances of the same device type, therefore global variables in these scripts are denied.
 
There are four possible functions for device script.




== Device scripting ==
== Consumables scripting ==
Devices uses effect scripts, which is similar to any object scripts, but uses itΓÇÖs own special system of arguments. These scripts are shared between instances of the same device type, therefore global variables in this scripts are denied.
{{Main|VoidExpanse/Consumable_scripting|Consumables scripting}}
Consumables can be programmed with standard xml-values, but, in order to implement something
special, one can use special techniques described in this article.


There are four possible functions for device script.
{{Modding}}

Latest revision as of 08:29, 20 April 2015

Scripting overview

Basic concepts

Scripting is done via actions that custom scripts can subscribe to. There are a number of actions that are called by servers automatically, plus users can create their own actions and call them when needed. This also makes it possible for users to create scripting frameworks/libraries for others to use. Each action has one argument (ΓÇ£argsΓÇ¥) that is a JavaScript object containing several properties depending on which action is being called. In some actions this ΓÇ£argsΓÇ¥ object can be empty. But either way, it allows for a unified format for all actions within the scripting system.

Scripting naming convention

  • String IDΓÇÖs in mods can only contain alphanumeric characters and underscores. Any other characters are illegal.
  • Use underscore for variables and properties.
  • Use CamelCase for functions and methods.
  • zxc_q - ΓÇ£qΓÇ¥ in the variable always represents ΓÇ£quantityΓÇ¥ or ΓÇ£number of ...ΓÇ¥.
  • zxc_id - ΓÇ£idΓÇ¥ always means either a string id from a XML file if it is of the type of string, or if it is a uint then it is an entity (instance) id of some object.
  • zxc_req - ΓÇ£reqΓÇ¥ always means ΓÇ£requirementsΓÇ¥.
  • All mods should prefix their variables, functions, classes, storage keys, etc with a key for isolation from other mods. An example of such a prefix would be ΓÇ£prf_ΓÇ¥ -> ΓÇ£prf_some_variableΓÇ¥, ΓÇ£prf_SomeFunctionΓÇ¥.

Internal scripts (Overridable)

Main article: Internal scripts
These scripts are usually only called once and only in a particular situation. Each of these script files must exist in only one instance. If a new script is added the previous one will be overridden. Each of the script files must implement only one script action. Usually players should not modify these scripts unless they want to completely re-implement some game feature.

Global scripts (called in the world dynamically)

Main article: Global scripts
Global scripts are executed continuously during gameplay. For each event there could be many bound scripts. Also it is possible to create custom actions and subscribe to them. Please note: OnInit() method is executed only for Global and Internal scripts.

Object scripts

Main article: Object scripts
Object scripts are scripts attached to a particular game object. When that object starts an action, if a script has an appropriate handler for this action it will be executed.

Events

List of Events


VoidExpanse Scripting API

Library inclusion and scopes usage

Preprocessor directive include(libname.js); includes a library script into the current JS instance. Library scripts can also include other libraries (no echo effect will appear).

Allows modders to use functions and objects of these libraries in this particular script instance.

  • Include directive must be the first lines in the script file (not necessarily, but preferably - to maintain order in scripts).
  • All include directives must be before the first function declaration in the file.

Preprocessor directive using(scopename); allows modders to use a specific scope in a specific script. Scope name must be an existing scope name (see scopes below). Except for some specific scopes (like topic or npc), which are available only in specific places, like topic scripts or AI behaviors.

Scopes

Each scope contains a number of functions available from it.

Device scripts

Main article: Device scripts
Devices uses effect scripts, which is similar to any object scripts, but uses itΓÇÖs own special system of arguments. These scripts are shared between instances of the same device type, therefore global variables in these scripts are denied.

There are four possible functions for device script.


Consumables scripting

Main article: Consumables scripting
Consumables can be programmed with standard xml-values, but, in order to implement something special, one can use special techniques described in this article.


VoidExpanse Modding (Edit template)

Using mods: Installing and using mods

Overview articles: Modding (main article), Package files structure

Topic specific articles: Assets modding, Content Modding, Scripting overview, Scripting API, Scripting Events system, Localization

Detailed scripting articles: Internal scripts, Global scripts, object scripts, Device scripts, Consumable scripting

Tools: VE Physics Adjuster, VE Mod Uploader (Steam), AT Localization Utility