Witcher Wiki
(Created page with "Witcher Script ''(.ws)'' is the primary scripting language for The Witcher 3: Wild Hunt. A very large chunk of the game's logic is written in Witcher Script, which is comp...")
 
m (Mentioning the evident ActionScript 3. The "AS3" strings in the executable aren't exactly the only indicator. Just look at the language details ... fits perfectly (and makes sense).)
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{stub}}
Witcher Script ''(.ws)'' is the primary scripting language for [[The Witcher 3: Wild Hunt]]. A very large chunk of the game's logic is written in Witcher Script, which is compiled on game startup. [[Modding Scripts in The Witcher 3|Mods can override scripts]] and thus can drastically change game behavior.
+
'''Witcher Script''' ''(.ws)'' is the primary scripting language for [[The Witcher 3: Wild Hunt]]. A very large chunk of the game's logic is written in Witcher Script. [[Modding Scripts in The Witcher 3|Mods can override scripts]] and thus can drastically change game behavior. Witcher Script is either based on or identical to ActionScript 3 (and very similar to [https://udn.epicgames.com/Three/UnrealScriptHome.html UnrealScript]).
  +
  +
The specification for ActionScript 3, which is also used in the Shockwave Flash file format and can be described as a dialect of ECMAScript, can be found in its [https://www.adobe.com/go/AS3LR/ official language reference] (unofficially [https://github.com/as3lang/ActionScript3/wiki/Specification also here], [http://web.archive.org/web/20171028212944/http://bloople.net/as3ls/ here] and [http://web.archive.org/web/20170606040559/http://bloople.net/ActionScript%203%20Language%20Specification.pdf here]).
  +
  +
Technically, Witcher Script is a [https://en.wikipedia.org/wiki/Strong_and_weak_typing strongly-typed], class-based [https://en.wikipedia.org/wiki/Object-oriented_programming object-oriented] programming language, though it supports functions declared outside of the scope of classes. It uses C-like [https://en.wikipedia.org/wiki/Control_flow control flow] with a single global [https://en.wikipedia.org/wiki/Namespace namespace]. Functions use pass-by-value by default for [[Witcher 3 Native Datatypes|native datatypes]] and structs, with the keyword <code>out</code> indicating pass-by-reference. Pass-by-reference is used for objects. Like C, Witcher Script is [https://en.wikipedia.org/wiki/Free-form_language free form], with semi-colons serving as statement terminators and curly brackets pairs defining groups of statements as well as scope. It is pre-compiled prior to runtime though it supports [[Script Studio#Line By Line Debugging|line-by-line debugging]].
  +
  +
Witcher Script doesn't appear to have function references, though it is possible to pass function names for callbacks, though this seems limited to the engine ''(see implementation of Initialize in [[W3Class CPlayerInput]] for example of this)''.
  +
  +
==Editors==
  +
{{Main|Notepad++|Script Studio}}
  +
  +
==Native Datatypes==
  +
{{Main|Witcher 3 Native Datatypes}}
  +
  +
==Novel Features==
  +
Some of the following information is ''speculation'' based on information in the scripts as well as information from other game engines. CDPR has been fairly mum about the inner workings of REDengine. If you know something, please edit the wiki so that the correct information is available!
  +
  +
===Timer Functions===
  +
Timer functions are functions that are periodically called on a timer while that timer is active. They are started with the functions <code>AddTimer</code> and stopped with the function <code>RemoveTimer</code>, both member functions of [[W3Class CEntity]]. It is likely that these start and stop timer functions only work if the script is "hooked" on to a native [[W3Class CEntity]]. Timer functions always take the parameters:
  +
  +
:<code>deltaTime : float, id : int</code>
  +
  +
<code>deltaTime</code> is probably the time since the last activation of the timer, while <code>id</code> is likely the id of the timer.
  +
  +
===Latent Functions===
  +
Latent functions are functions that execute over more than one game tick. They use either the global functions <code>Sleep</code> or <code>SleepOneTick</code>, or call other latent functions (including native ones!) that do. These functions can only be called from inside another latent function or from a state's <code>entry</code> functions.
  +
  +
===exec/storyscene/quest Functions===
  +
Global functions declared with one of these modifiers will be available to different portions of the game to execute. Generally speaking, only exec functions are interesting to modders, as it allows modders to add console commands to the game.
  +
  +
* [[Witcher 3 Exec Functions|exec functions]] are available to the [[The Witcher 3 console mode|debug console]]
  +
* [[Witcher 3 Storyscene Functions|storyscene functions]] are likely accessible to cutscenes
  +
* [[Witcher 3 Quest Functions|quest functions]] are likely accessible to quests
  +
  +
===Editor Specific===
  +
====default====
  +
This declares a default value for a class field.
  +
  +
====editable====
  +
Likely, this means that this class field is available for editing in the REDkit 2 editor.
  +
  +
===Statemachine Classes===
  +
Classes defined with the <code>statemachine</code> keyword are able to take on states, which are special kinds of classes that override behavior (i.e. functions/events) in their parent while the <code>statemachine</code> class in in the child <code>state</code>. A <code>statemachine</code> class transitions between states and keeps a running [https://en.wikipedia.org/wiki/Stack_(abstract_data_type) stack]. All <code>statemachine</code> classes must eventually inherit from [[W3Class IScriptable]] and that class contains applicable functions.
  +
  +
====Entry Functions====
  +
Functions within a <code>state</code> can be declared as <code>entry</code> functions. <code>entry</code> functions are also <code>latent</code>, though it isn't clear what else this denotes.
  +
  +
====virtual_parent====
  +
In states, there is some distinction between <code>parent</code> and <code>virtual_parent</code>.
   
 
==Keywords==
 
==Keywords==
  +
{{cols|5|
===Access Limitations===
+
====Access Limitations====
 
*private
 
*private
 
*protected
 
*protected
 
*public
 
*public
   
===Control Flow===
+
====Control Flow====
 
*if
 
*if
 
*else
 
*else
Line 16: Line 66:
 
*return
 
*return
 
*break
 
*break
  +
*continue
   
===Inheritance===
+
====Inheritance====
 
*extends
 
*parent
 
*parent
 
*virtual_parent
 
*virtual_parent
Line 23: Line 75:
 
*super
 
*super
   
===Boolean===
+
====Boolean====
 
*true
 
*true
 
*false
 
*false
   
===Nullability===
+
====Nullability====
 
*NULL
 
*NULL
   
===Declarations===
+
====Declarations====
 
*var
 
*var
 
*enum
 
*enum
Line 38: Line 90:
 
*class
 
*class
   
====Declaration Modifiers====
+
=====Declaration Modifiers=====
  +
*abstract
 
*statemachine
 
*statemachine
 
*default
 
*default
 
*editable
 
*editable
*extends
 
 
*const
 
*const
 
*import
 
*import
Line 48: Line 100:
 
*timer
 
*timer
 
*exec
 
*exec
  +
*quest
  +
*storyscene
 
*saved
 
*saved
*in
 
 
*out
 
*out
 
*entry
 
*entry
   
===Native Datatypes===
+
====Memory Management====
*int
 
*bool
 
*name
 
*float
 
*string
 
*hint
 
*Vector
 
*Uint64
 
*array
 
 
===Memory Management===
 
 
*new
 
*new
 
*delete
 
*delete
 
*in
  +
}}
  +
  +
[[Category:The Witcher 3 modding]] __NOEDITSECTION__

Revision as of 22:22, 15 July 2019

Substances Graveir bone
Expansion required
This article is too short to provide more than rudimentary information about the subject. You can help Witcher Wiki by expanding it.

Witcher Script (.ws) is the primary scripting language for The Witcher 3: Wild Hunt. A very large chunk of the game's logic is written in Witcher Script. Mods can override scripts and thus can drastically change game behavior. Witcher Script is either based on or identical to ActionScript 3 (and very similar to UnrealScript).

The specification for ActionScript 3, which is also used in the Shockwave Flash file format and can be described as a dialect of ECMAScript, can be found in its official language reference (unofficially also here, here and here).

Technically, Witcher Script is a strongly-typed, class-based object-oriented programming language, though it supports functions declared outside of the scope of classes. It uses C-like control flow with a single global namespace. Functions use pass-by-value by default for native datatypes and structs, with the keyword out indicating pass-by-reference. Pass-by-reference is used for objects. Like C, Witcher Script is free form, with semi-colons serving as statement terminators and curly brackets pairs defining groups of statements as well as scope. It is pre-compiled prior to runtime though it supports line-by-line debugging.

Witcher Script doesn't appear to have function references, though it is possible to pass function names for callbacks, though this seems limited to the engine (see implementation of Initialize in W3Class CPlayerInput for example of this).

Editors

Main articles: Notepad++ and Script Studio

Native Datatypes

Novel Features

Some of the following information is speculation based on information in the scripts as well as information from other game engines. CDPR has been fairly mum about the inner workings of REDengine. If you know something, please edit the wiki so that the correct information is available!

Timer Functions

Timer functions are functions that are periodically called on a timer while that timer is active. They are started with the functions AddTimer and stopped with the function RemoveTimer, both member functions of W3Class CEntity. It is likely that these start and stop timer functions only work if the script is "hooked" on to a native W3Class CEntity. Timer functions always take the parameters:

deltaTime : float, id : int

deltaTime is probably the time since the last activation of the timer, while id is likely the id of the timer.

Latent Functions

Latent functions are functions that execute over more than one game tick. They use either the global functions Sleep or SleepOneTick, or call other latent functions (including native ones!) that do. These functions can only be called from inside another latent function or from a state's entry functions.

exec/storyscene/quest Functions

Global functions declared with one of these modifiers will be available to different portions of the game to execute. Generally speaking, only exec functions are interesting to modders, as it allows modders to add console commands to the game.

Editor Specific

default

This declares a default value for a class field.

editable

Likely, this means that this class field is available for editing in the REDkit 2 editor.

Statemachine Classes

Classes defined with the statemachine keyword are able to take on states, which are special kinds of classes that override behavior (i.e. functions/events) in their parent while the statemachine class in in the child state. A statemachine class transitions between states and keeps a running stack. All statemachine classes must eventually inherit from W3Class IScriptable and that class contains applicable functions.

Entry Functions

Functions within a state can be declared as entry functions. entry functions are also latent, though it isn't clear what else this denotes.

virtual_parent

In states, there is some distinction between parent and virtual_parent.

Keywords

Access Limitations

  • private
  • protected
  • public

Control Flow

  • if
  • else
  • for
  • switch
  • case
  • while
  • return
  • break
  • continue

Inheritance

  • extends
  • parent
  • virtual_parent
  • this
  • super

Boolean

  • true
  • false

Nullability

  • NULL

Declarations

  • var
  • enum
  • struct
  • function
  • event
  • class
Declaration Modifiers
  • abstract
  • statemachine
  • default
  • editable
  • const
  • import
  • final
  • timer
  • exec
  • quest
  • storyscene
  • saved
  • out
  • entry

Memory Management

  • new
  • delete
  • in

Access Limitations

  • private
  • protected
  • public

Control Flow

  • if
  • else
  • for
  • switch
  • case
  • while
  • return
  • break
  • continue

Inheritance

  • extends
  • parent
  • virtual_parent
  • this
  • super

Boolean

  • true
  • false

Nullability

  • NULL

Declarations

  • var
  • enum
  • struct
  • function
  • event
  • class
Declaration Modifiers
  • abstract
  • statemachine
  • default
  • editable
  • const
  • import
  • final
  • timer
  • exec
  • quest
  • storyscene
  • saved
  • out
  • entry

Memory Management

  • new
  • delete
  • in