Doomsday Script reference

From Doomsday Wiki
Revision as of 21:10, 15 November 2015 by Skyjake (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article describes the Doomsday Script language and its role in the Doomsday 2 architecture.

Overview

As a scripting language, Doomsday Script serves in many roles, including user interface and menu functionality, configuration (cf. traditional cvars), high-level game logic (cf. Hexen ACS; XG), and game data definitions.

Doomsday Script is not a compiled language and thus is not intended for high-performance or time-critical tasks. Game plugins written in native code should be used for processing-intensive functionality.

Example:

def exampleFunc(a)
    if a
        return "It is true!"
    else
        return "Nay, it is false."
    end
end
print exampleFunc(True)

The syntax of the language is heavily influenced by Ruby and Python, with a few notable differences:

  • The amount of indentation whitespace has no meaning. Compounds are explicitly closed with end (Keyword).
  • A colon (:) always indicates a single-line compound that does not need to be closed:
    def func2(): return 'World'
  • "Objects" are classless and called records. They correspond native de::Record instances:
    record myrec
    myrec.newMember = 100
  • There are no non-modifiable tuples, just arrays:
    array = [1, 2, 3, 4]
    array[1] = 100
    # array is now [1, 100, 3, 4]
  • 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.

Built-in types

  • Number
  • Text
  • Time
  • Array
  • Dictionary
  • Function
  • Record

Built-in constants

  • True
  • False
  • None
  • Pi

Built-in functions

Function Description
deserialize (Function) reconstruct data from an array of bytes
dictkeys (Function) returns the keys of a dictionary as an array
dictvalues (Function) returns the values of a dictionary as an array
dir (Function) returns the variable names of a namespace as an array
eval (Function) parses and executes argument as a script, returns result
File (Function) returns a Core.File object
floor (Function) rounds a number down to an integer
globals (Function) returns the global namespace as a record
len (Function) determines the length/size of the argument
locals (Function) returns the local namespace as a record
members (Function) returns the members of a record as a dictionary
Number (Function) converts argument to a number value
Record (Function) duplicates a record or creates an empty one
serialize (Function) serializes data into an array of bytes
subrecords (Function) returns the subrecords of a record as a dictionary
Text (Function) converts argument to a text string
Time (Function) converts argument to a time
timedelta (Function) calculates difference between two times (as seconds)
typeof (Function) returns type of value as a text string

Feature walkthrough

Standard library modules

The Doomsday Script Standard Library consists of a collection of native built-in modules and script modules.

See also