User Tools

Site Tools


script:reference

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
script:reference [2018-12-15 22:12]
skyjake
script:reference [2019-11-18 12:59]
skyjake
Line 1: Line 1:
 +====== Doomsday Script reference guide ======
 +
 +This article describes the Doomsday Script language and its role in [[:Doomsday 2]].
 +
 +===== Overview =====
 +
 +Doomsday Script in used for several things internally, for example managing engine configuration and controlling [[assets:​model#​timelines|3D model asset animation]]. Doomsday Script is not a compiled language and thus is not intended for high-performance or time-critical tasks. Game plugins, for instance, should be written in native code.
 +
 +Below is an example of the syntax:
 +
 +  def exampleFunc(a)
 +      if a
 +          return "It is true!"
 +      else
 +          return "Nay, it is false."​
 +      end
 +  end
 +  print exampleFunc(True)
 +
 +
 +The syntax is heavily influenced by Python and Ruby, with a few notable differences:​
 +
 +  * The amount of indentation whitespace has no meaning. Compounds are explicitly closed with ''​end''​.
 +  * A colon ('':''​) always indicates a single-line compound that does not need to be closed: <​code>​def func2(): return '​World'</​code>​
 +  * Objects are weakly typed: they may have one or more superclass objects that provide common members, but otherwise there is no type safety or checking. Objects are called [[Record]]s and they represent native ''​de::​Record''​ instances:<​code>​record myrec
 +myrec.newMember = 100</​code>​
 +  * There are no non-modifiable tuples, just arrays:<​code>​array = [1, 2, 3, 4]
 +array[1] = 100
 +# array is now [1, 100, 3, 4]</​code>​
 +  * There are a couple of special assignment operators. Global assignment ('':​=''​) will assign into variables in parent scopes if no local variable with the given name is found. Weak assignment (''?​=''​) will only assign a value if a variable has not yet been created.
 +
 +===== Examples =====
 +
 +  *  [[https://​github.com/​skyjake/​Doomsday-Engine/​blob/​master/​doomsday/​tests/​test_script/​kitchen_sink.ds|The "​Kitchen Sink" test script]]
 +  * [[https://​github.com/​skyjake/​Doomsday-Engine/​blob/​master/​doomsday/​apps/​client/​net.dengine.client.pack/​modules/​controllers.ds|Game controller presets script]]
 +
 +===== Using Doomsday Script =====
 +
 +As of [[version:​2.2]],​ scripts can be used for the following:
 +
 +  * **Animating 3D models:**
 +    * [[assets:​scripting_with_stateanimator|Initializing the animator of a thing (onInit)]]
 +    * [[assets:​scripting_with_stateanimator|When receiving damage or when the thing state changes]]
 +    * [[assets:​model#​timelines|At specific points in time]]
 +    * Manipulate shader variables, render passes, and the active material
 +  * **Application:​**
 +    * Loading fonts
 +    * Callbacks for game load/unload
 +  * **Configuration:​**
 +    * [[https://​git.skyjake.fi/​doomsday/​engine/​src/​branch/​master/​doomsday/​sdk/​libcore/​net.dengine.stdlib.pack/​modules/​Config.ds|Applications run a Config.ds script at startup]]
 +    * [[https://​git.skyjake.fi/​doomsday/​engine/​src/​branch/​master/​doomsday/​apps/​client/​net.dengine.client.pack/​modules/​bootstrap.ds|Client runs bootstrap.ds when initialization is complete (e.g., maintenance during upgrades, SF2 soundfont caching)]]
 +  * **Console:​**
 +    * [[.module:​console|List,​ get, and set cvars]]
 +    * [[guide:​task_bar_and_console#​console|Interactive scripting prompt (toggle in taskbar)]]
 +  * **Definitions:​**
 +    * [[script:​module:​defs#​lookups|Accessing currently loaded DEDs via the Defs module]]
 +  * **Files:**
 +    * Reading/​writing files and folders using File objects
 +  * **Game:**
 +    * [[.module:​Game|Show a HUD message]]
 +  * **Input:**
 +    * Binding controls and events (e.g., Input.bindEvent)
 +    * [[https://​git.skyjake.fi/​doomsday/​engine/​src/​branch/​master/​doomsday/​apps/​client/​net.dengine.client.pack/​modules/​controllers.ds|Game controller presets]]
 +  * **Packages:​**
 +    * [[fs:​packages#​metadata|Modify package metadata and assets (__init.ds__)]]
 +    * [[fs:​packages#​scripting|Adding modules to the import path]]
 +    * [[fs:​packages#​scripting|onLoad/​onUnload callbacks]]
 +  * **Things:**
 +    * [[.module:​World#​World.Thing|Query hit points]]
 +    * [[.module:​World#​World.Thing|Start a sound]]
 +    * [[ded:​thing#​on_touch|"​On touch" script]]
 +
 +===== Language reference =====
 +
 +See the [[language|Language reference]] for information about the syntax, and  built-in functions and modules.
  
script/reference.txt ยท Last modified: 2020-04-04 08:04 by skyjake