Difference between revisions of "Scripting"

From Divinity Engine Wiki
Jump to: navigation, search
(Created page with "<h1><u>Introduction</u></h1> The scripting system is currently used for the behaviour of characters and items. For characters this is only part of the behaviour, as many more...")
 
Line 1: Line 1:
 
<h1><u>Introduction</u></h1>
 
<h1><u>Introduction</u></h1>
The scripting system is currently used for the behaviour of characters and items. For characters this is only part of the behaviour, as many more systems are influencing this in the following priority:
+
<p>The scripting system is currently used for the behaviour of characters and items. For characters this is only part of the behaviour, as many more systems are influencing this in the following priority:</p>
 
<ul><li>Story: executing Osiris Tasks</li>
 
<ul><li>Story: executing Osiris Tasks</li>
 
<li>Dialogs: dialog behaviour and animations</li>
 
<li>Dialogs: dialog behaviour and animations</li>
 
<li>Statuses: dying, frozen, petrified, ...</li>
 
<li>Statuses: dying, frozen, petrified, ...</li>
 
<li>Scripts: executing the current reaction or scriptframe</li></ul>
 
<li>Scripts: executing the current reaction or scriptframe</li></ul>
Scripts are the lowest priority and will only execute if none of the other systems want to do something. For items it's a lot simpler, as the scripting system is the only thing that influences the items behaviour.
+
<p>Scripts are the lowest priority and will only execute if none of the other systems want to do something. For items it's a lot simpler, as the scripting system is the only thing that influences the items behaviour.</p>
 +
 
 +
<h1><u>Sections</u></h1>
 +
<p>Before any section in a script, we can INCLUDE files. When you INCLUDE a file, you're telling the system to parse that file first.</p>
 +
 
 +
<h2><u>INIT</u></h2>
 +
<p>In the INIT section you can declare global variables and inherit from other scripts. Global variables always start with&nbsp;% and can be accessed and modified everywhere (including other scripts, osiris, and in code). There are also EXTERN variables, which are exposed when you assign a script to an object so you can change the value for local instances of the script. The INIT section also contains the special variable '__Me', which contains the owner of the script. This is a character or item depending on the script type. Code will automatically fill this variable.<br>
 +
Inheritance is done with the USING keyword and copies everything from the other script into the current script. This includes all global variables, reactions, scriptframes, and events. You can use USING SHARED if you intend to overwrite reactions, events, or scriptframes.<br>
 +
An example INIT section:</p>
 +
<div class="sites-codeblock sites-codesnippet-block">
 +
<pre>INIT
 +
    USING SHARED Base
 +
    CHARACTER:__Me
 +
    CHARACTER:%AnotherCharacter=null
 +
    FLOAT3:%CurrentPosition=null
 +
    EXTERN INT:%CanRun=1
 +
</pre>
 +
 
 +
<p>If you want to override a specific reaction, event, or scriptframe you have to specify this with the OVERRIDE keyword:</p>
 +
<pre>
 +
REACTION TestReaction, 5 OVERRIDE
 +
EVENT TestEvent OVERRIDE
 +
SCRIPTFRAME TestFrame OVERRIDE
 +
</pre>
 +
<p>If needed, you can also only inherit specific reactions, events, orscriptframes:</p>
 +
<div></div>
 +
<pre>
 +
USING ScriptName REACTION ReactionName,NewPriority
 +
USING ScriptName EVENT EventName
 +
USING ScriptName SCRIPTFRAME ScriptFrameName
 +
</pre>

Revision as of 12:45, 8 September 2017

Introduction

The scripting system is currently used for the behaviour of characters and items. For characters this is only part of the behaviour, as many more systems are influencing this in the following priority:

  • Story: executing Osiris Tasks
  • Dialogs: dialog behaviour and animations
  • Statuses: dying, frozen, petrified, ...
  • Scripts: executing the current reaction or scriptframe

Scripts are the lowest priority and will only execute if none of the other systems want to do something. For items it's a lot simpler, as the scripting system is the only thing that influences the items behaviour.

Sections

Before any section in a script, we can INCLUDE files. When you INCLUDE a file, you're telling the system to parse that file first.

INIT

In the INIT section you can declare global variables and inherit from other scripts. Global variables always start with % and can be accessed and modified everywhere (including other scripts, osiris, and in code). There are also EXTERN variables, which are exposed when you assign a script to an object so you can change the value for local instances of the script. The INIT section also contains the special variable '__Me', which contains the owner of the script. This is a character or item depending on the script type. Code will automatically fill this variable.
Inheritance is done with the USING keyword and copies everything from the other script into the current script. This includes all global variables, reactions, scriptframes, and events. You can use USING SHARED if you intend to overwrite reactions, events, or scriptframes.
An example INIT section:

INIT
     USING SHARED Base
     CHARACTER:__Me
     CHARACTER:%AnotherCharacter=null
     FLOAT3:%CurrentPosition=null
     EXTERN INT:%CanRun=1

If you want to override a specific reaction, event, or scriptframe you have to specify this with the OVERRIDE keyword:

REACTION TestReaction, 5 OVERRIDE
EVENT TestEvent OVERRIDE
SCRIPTFRAME TestFrame OVERRIDE

If needed, you can also only inherit specific reactions, events, orscriptframes:

USING ScriptName REACTION ReactionName,NewPriority
USING ScriptName EVENT EventName
USING ScriptName SCRIPTFRAME ScriptFrameName