Incom Corporation
  2026 active members
  202 are Online

Year

25

Day

320

Time

10:00:27

Guest
Login
Last Updated: Year 25 Day 170
NPCs: Scripts

SWC uses an in-house language for scripting in game entities (currently only NPCs, items, droids, and quests, but eventually much more) based on a combination of concepts taken from the programming languages LISP and Scheme. LISP was originally described by John McCarthy in 1960. A PDF version of its technical and formal description is available online, but you don't need to (and probably don't want to) read it in order to start using the language.

Most scripts for in game entities are written by the NPC team, but some entities, such as Custom NPCs and Protocol Droids can have their scripts edited by players.

You can access the NPC script editor through the NPC Inventory, any custom NPCs that you have permission to edit the scripts for will have an Edit Script link available.

This language is designed for syntactical simplicity and clarity. It is composed entirely of S-Expressions, which are defined by either a single "atom" or a list of multiple atoms. An atom is a single value, like a number, string, or variable name (usually called a symbol). Symbols can contain most characters except for spaces, semicolons, single or double quotes, parentheses, and brackets (others may be added to this exception list if they are used for future language extensions). S-Expressions group atoms within parentheses to form lists; therefore all of these are valid S-Expressions:

Code
10
(1 10)
x
(x 5 "this string is one atom")

Each S-Expression is evaluated in exactly the same way--there is only one syntactical form for instructions in SWC Lisp. If the S-Expression is a single atom, it evaluates to itself or its defined value if it is a symbol. Thus 42 evaluates to 42, while x evaluates to the previously assigned value for x. If it is a list, then the first element of the list determines which operation is to be performed on the rest of the list. Effectively, the first element selects a function to be evaluated with the remaining elements as arguments. For example, to add together some numbers:

Code
(+ 1 2)

This evaluates to 3. S-Expressions can be nested and they will be resolved from the inside out. There is no operator precedence to remember in SWC Lisp, because the grouping of S-Expressions makes the exact sequence of evaluation explicit. Each S-Expression can be evaluated and substituted into an outer S-Expression until a single value is left:

Code
(+ 1 (* (- 2 1) (+ 1 2)))
(+ 1 (* 1 3))
(+ 1 3)
4

Although the syntax is completely regular, there are a few special statements that do not correspond to "function" calls: instead they define the necessary language constructs required to make a programming language. We will encounter two of these used to create variables and functions.

SWC Lisp also supports comments, which begin with a ; and continue to the end of the line.

Code
; This is a comment, and will not be executed.

Like other languages, SWC Lisp allows you to define variables and functions. A variable is created by calling defvar with a symbol and a value:

Code
(defvar x 1)

This defines a variable named x with the value 1. It can be used in subsequent statements as a normal number would be:

Code
(+ x 1)
; Produces 2

The value of a variable can be changed with set!:

Code
(defvar x 1)
(set! x (+ x 1))
(+ x 1)
; Produces 3
Note
Functions that have side effects (modify things) are usually named with a ! suffix. Functions that are predicates that return a boolean are named with a ? suffix.

Be aware that during a script execution, variable values will not persist across conversation interactions. For variable values to persist between invocations, you must use a Persistent Variable (covered later).

Functions are defined using the defun form and two arguments: the function declaration, consisting of a name and possibly argument names, and a function body. For example, a function that adds one to its argument:

Code
(defun (incr x)
  (+ x 1))

Whenever a linebreak occurs inside an S-Expression, it is customary to indent the following lines by two additional spaces, in order to improve clarity. Trailing parenthesis are included on the final line. Extra whitespace (spaces, tabs, newlines, etc.) are all ignored by the interpreter. This function can now be called with any argument desired, including other lists as before:

Code
(incr 1)
; Produces 2

(incr x)
; Produces 2

(incr (* 2 3))
; Produces 7

If a function does not take any arguments, it should be defined with an atom for the name. It may seem pointless to define a function without arguments, but when we create functions that do things (such as displaying messages to the player), rather than simply calculate things, it is often useful to group a series of operations into a single function for convenience if they need to be repeated. Additionally, multiple statements can be included in a function body. All of them will be executed, but the value of the final statement will used for the function's value. Examples of both of these situations will be shown below.

Additionally, a function may declare optional arguments along with a default expression by putting a pair of the form (name default) in place of the argument name. This default environment expression is evaluated at call time if the default value is needed. Default values cannot reference earlier arguments; they are evaluated in the scope in which the function was defined. This is illustrated in the example below.

Code
(defun (repeat
         activity   ; Activity is still required
         (count 1)) ; Count is optional and will have the value 1 if not specified
  (cond
    [(le? count 1) (activity)]
    [#t (activity) (repeat activity (- count 1))]))

; Calls show-info once
(repeat show-info)

; Calls show-info five times
(repeat show-info 5)

The (apply func arglist) function can be used to call functions dynamically. This function allows you to specify the arguments as a list. The following example calls are equivalent:

Code
(+ 1 2 3 4 5)
(apply + (list 1 2 3 4 5))
(let
    [
        (my-func +)
        (my-args (list 1 2 3 4 5))
    ]
    (apply my-func my-args)
)

1.1.1/ Is Defined

(is-defined? name) returns true if the symbol name is defined (either as a variable with set/defvar/let or as a callable function with defun), false otherwise.

Code
(defined? shipsA)
; evaluates to False

(defvar shipsA (list "X-Wing" "Y-Wing" "B-Wing"))
(defined? shipsA)
; evaluates to True

1.1.2/ Map

(map fn list): list is used to apply a function to each element of a list, it produces a new list with the results of the application. Example shows a function that multiplies each element of a list by 2. Note the original list is unchanged, and a new list is produced:
Code
(defvar my-input (list 1 2 3 4 5))
(defun (double x)
  * x 2)
(map double my-input)
; Produces (list 2 4 6 8 10)

Can be used with a lambda:

Code
(defvar my-input (list 1 2 3 4 5))
(map (lambda (x) (* x 2)) my-input)
; Produces (list 2 4 6 8 10)

1.1.3/ Filter

(filter fn list): list filters an input list and returns a new list consisting of the members where the supplied predicate returns true.

Code
(defvar my-input (list 1 2 3 4 5 6))
(defun (is-even x)
  (eq? (modulo x 2) 0)
)
(filter is-even my-input)
; Produces (list 2 4 6)

Can be used with an lambda:

Code
(defvar my-input (list 1 2 3 4 5 6))
(filter (lambda (x) (eq? (modulo x 2) 0)) my-input)
; Produces (list 2 4 6)

1.1.5/ Foreach

(foreach fn list) executes a function for each element in a list. Unlike map, this function does not return any value.

Code
(defvar my-input (list "X-Wing" "Y-Wing" "B-Wing"))
(foreach (lambda (ship)
  (say ship)
) my-input)

1.1.6/ Append Element

(append-element list element): list returns a new list that has element appended to the end.

(append-element! list element): list modifies the given list by appending element to the end. append-element! returns the list.

Code
(defvar ships (list "X-Wing" "Y-Wing" "B-Wing"))

(append-element ships "TIE Fighter")
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter") without changing ships

; Note the difference between append-element and cons:
(cons ships "TIE Fighter")
; Produces (("X-Wing" "Y-Wing" "B-Wing") . "TIE Fighter")

(append-element! ships "TIE Fighter")
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter")
(append-element! ships "TIE Interceptor")
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter" "TIE Interceptor")

1.1.7/ Append List

(append-lists list1 list2 list3 ...): list produces a new list that is the given lists concatinated together.

(append-lists! list1 list2 list3 ...): list modifies the given lists and joins them together in place. Returns the first list.

Code
(defvar shipsA (list "X-Wing" "Y-Wing" "B-Wing"))
(defvar shipsB (list "TIE Fighter" "TIE Interceptor"))
(defvar shipsC (list "Bulk Freighter" "Y-8 Mining Vessel"))

(append-lists shipsA shipsB)
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter" "TIE Interceptor")

(append-lists shipsA shipsB shipsC)
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter" "TIE Interceptor" "Bulk Freighter" "Y-8 Mining Vessel")

; Note the difference between append-lists and cons:
(cons shipsA shipsB)
; (("X-Wing" "Y-Wing" "B-Wing") "TIE Fighter" "TIE Interceptor")

(append-lists! shipsA shipsB)
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter" "TIE Interceptor")
(append-lists! shipsA shipsC)
; Produces ("X-Wing" "Y-Wing" "B-Wing" "TIE Fighter" "TIE Interceptor" "Bulk Freighter" "Y-8 Mining Vessel")
; Notice how shipsA and shipsB are modified in place and joined together and shipsC is joined to the end.

Variables can also be "quoted" by placing a single quote before the symbol. This indicates to the interpreter that this specific mention of this symbol should not be evaluated and instead used as a literal string, but if it is evaluated a second time, it will be used to look up a variable name. This has a number of important uses, most of which are beyond the scope of this introduction, but it is necessary in order to access the persistent variables. Expressions can be quoted as well, in which case a literal list containing exactly the values specified is produced.

Code
; Both of these produce the same result, a list containing the literal symbols a, b, and c
(list 'a 'b 'c)
'(a b c)

Or, variables can be "quasiquoted" by placing a backtick (`) in front. This applies to expressions as well. The difference is that elements inside an expression that has been quasiquoted can be unquoted by prepending a comma (,) before the element to be unquoted, causing them to be evaluated, even though the rest of the expression is not. This is best illustrated with an example,

Code
`(a b ,(+ 1 2))
; The result is (a b 3), because the first two symbols are not evaluated but the last expression is

Quasiquoting is primarily a shorthand used to simplify complex nested lists that may require a mixture of evaluated and unevaluated information to be combined.

In addition to globally visible variables created with `defvar`, it is possible to create local variables. In this case, the `let` form is used to define a new variable in a local scope. These variables take precedence over any other variables that might share the same name, but they do not refer to the same underlying value.

Note
Temporary variables only exist within the environment in which they are defined.

Code
(let ((nexta (+ a 1))
      (doublea (* a 2)))
  ; Here we can evaluate nexta and doublea, for instance using dbg-pp to see their values
  (dbg-pp nexta doublea))
; Here nexta and doublea are not defined!

When referencing a variable inside a local scope, the name resolution happens "inside out." The innermost scope is checked first, then the next one outside of it, and so on. This means it is possible to shadow function arguments inside a `let` block but preserve their value outside of it. You may nest as many local scopes as you like but it is easier to understand if all local variables are defined at once where possible.

Code
(defun (test x)
  (dbg-pp x) ; Will print the argument
  (let ((x (+ x 1)))
    (dbg-pp x))) ; Will print the argument + 1 instead even though they use the same name!

From a more technical perspective, let is functionally equivalent to let* as defined in scheme and racket. A variable may be used immediately after it has been bound within the same declaration block, rather than requiring nesting. let does not support letrec-type recursive binding or mutual binding.

SWC Lisp supports the manipulation of functions as a data type. That means that after a function is created with defun, it can be manipulated as a normal variable, including being passed to another function as an argument (this behavior may be familiar to you from a language such as Javascript, but it has enjoyed increased adoption in many major languages). However, you may also wish to create functions locally or create functions with some saved internal values.A

A function can be declared with the lambda expression form, which is very similar to the defun syntax described above except that the function does not have a name. A (trivial) function that adds together its two arguments can be defined like this

Code
(lambda (x y)
  (+ x y))

Alone the lambda syntax is not very interesting. However, a lambda expression can bind local variables, creating a closure, which can then be used in another context. For example, with defun we can create a "factory" function which produces other functions that have templated behavior.

Code
(defun (incr-factory offset)
  (lambda (x)
    (+ x offset)))

(defvar plustwo (incr-factory 2))
(dbg-pp (plustwo 1))
3

In this example the function `incr-factory` evaluates to another function, rather than a number or other simple value, allowing us to create multiple functions that can be evaluated again to produce an offset. The use of lambda functions and closures is a more advanced feature but can be used to create very sophisticated npc script systems.

Important
Functions created with lambda cannot be passed to as arguments to add-response or add-action

We will be working to improve the argument passing capabilities of add-response and add-action in order to create opportunity for more dynamic, parameterizable user interactions, but for now it is not possible to pass closures to these functions, nor is it possible to pass additional arguments.

1.5.1/ Cond

SWC Lisp supports cond, which evaluates a series of tests and then executes the body statements for the first test that produces a true value. With some hypothetical helper functions we can produce the next largest even number for any input:

Code
(defun (next-even x)
  (cond
    [(even? x) x]
    [#t (+ x 1)]))

In this case, square brackets are used, rather than parentheses, to denote each of the possible conditions. This is purely cosmetic and done to increase the readability of the language. Each condition list consists of a test S-Expression as the first element. If it produces a true value, all of the remaining S-Expressions in the body of that condition are evaluated. This also introduces the constant "#t" which is always true. A cond statement must always have a condition that always evaluates to true or an error is produced. This statement can be empty if need be.

A set of Boolean functions is also available which allows the user to combine logical expressions into compound conditions: `and`, `not`, and `or`. Comparison operators are also available for equality testing between two atoms (`eq?`) or numerical comparison (`ge?` `le?` `lt?` `gt?` for the traditional math operator versions `>=`, `<=`, `<`, and `>`).

Note

Predicates are usually named with trailing ? to indicate to the programmer that they ask yes/no questions and produce true or false values. This is a convention, not a language requirement.

1.5.2/ If

The if statement is the simplest conditional statement:

Code
(if (predicate)
  (run-on-true)
  (run-on-false)
)

predicate and run-on-true are required, run-on-false is optional.

1.6.1/ fmt

Building strings is simplified with the fmt builtin. Variables specified within curley brackets will be inserted into the format string.

Code
(defvar a "Hello")
(defvar b "World")
(fmt "{a}, {b}!")
; Produces the string "Hello, World!"

(let
  [
    (msg "Insufficient Credits")
  ]
  (fmt """{character}: <span class="warning">{msg}<span>""")
)
; Produces the string: "Character Handle: <span class="warning">Insufficient Credits<span>"
; This example shows using triple quoting string syntax to produce HTML output.

Now that the language is defined, we can use it to build NPC scripts. At their core, NPC scripts consist of a set of function definitions that print messages to the user and offer opportunities for further interaction, which is done using two built-in functions: `say` and `add-response`. All scripts start with a call to a function named `start` when the "interact" button is pressed on the in-game UI. Let's make a simple NPC script that displays a message and offers the user a chance to respond, and then he introduces himself.

Code
(defun start
  (say "Hi there.")
  (add-response "Hello, who are you?" my-name))

(defun my-name
  (say (concat "My name is " (get-name self))))

The first function, `start`, has two function calls in its body. `say` is used to show the given string to the player. "add-response" creates an option for the player to respond with the string given as its first argument ("Hello, who are you?"), and when the player selects this option, the function given as the second argument is called (the function corresponding to the symbol my-name).

The second function, `my-name`, is called after the player has chosen her response. It concatenates a fixed string with the NPC's name to create a message to be displayed to the user. Because this function does not add any responses, the player only sees the option to terminate the conversation.

Passive conversational NPCs can be built using only the `say` and `add-response` functions. The functions `describe` and `ooc` are also available to display a message as description or as OOC-styled text indicating extra instructions that may be relevant to the player. A non-verbal action to be taken by the player may be created with `add-action`.

Note

Most of the interesting NPC interactions, relating to quests, asset transfer, etc. are not yet available to custom NPCs. A suitable permission system will be created to prevent abuse before custom NPCs will be able to modify quest status. The description given here is for reference, planning, and for NPC team members who may be working on quest scripts that have the appropriate access.

There are other primitive operations available to NPCs, depending on script context. Quest-type NPCs have the ability to modify the character's quest status, including distributing rewards. Quests are defined as a series of objectives, where some objectives may be sub-objectives to be completed as part of another quest. Quest progression can be nonlinear and there are no requirements on the order of completion of sub-objectives in order to complete a parent quest. To manipulate the quest data corresponding to the currently interacting character, the procedure is simple. First, obtain references to the quest objectives (by ID) that a particular script will be modifying:

Code
(defvar super-hunter (get-quest 100))
(defvar rancor-stage (get-quest 101))
(defvar strider-stage (get-quest 102))
(defvar slug-stage (get-quest 103))

Then, as part of the NPC's interactions with the player, call one of `quest-start`, `quest-finish`, or `quest-fail` to change the quest's status.

Code
(defun start
  (say "Are you ready to hunt some big game?")
  (add-response "Absolutely, I live for slaughter." gogogo)
  (add-response "No way, I prefer cuddling" pacifist))

(defun pacifist
  (say "We have no place for your kind here."))

(defun gogogo
  (say "OK, first I need you to bring me 10 rancor trophies.")
  (quest-start super-hunter)
  (quest-start rancor-stage))

Of course, this NPC would ask the player if he wanted to begin hunting every time that the two interacted, which is usually undesirable. Instead, we could use conditions to ask about the player's progress instead if he has already begun the hunting quest, by using a set of predicates that test quest state (`quest-active?`, `quest-failed?` and `quest-finished?`):

Code
; Earlier definitions omitted
(defun start
  (cond
    [(quest-active? super-hunter) (show-quest-status)]
    [#t (introduce-quests)]))

(defun introduce-quests)
  (say "Are you ready to hunt some big game?")
  (add-response "Absolutely, I live for slaughter." gogogo)
  (add-response "No way, I prefer cuddling" pacifist))

(defun show-quest-status
  (cond
    [(quest-active? rancor-stage) (rancor-stats)]
    [(quest-active? strider-stage) (strider-stats)]
    [(quest-active? slug-stage) (slug-stats)]))

(defun rancor-stats
  ; ... show progress on the rancor killing quest, using q-vars
  ; which are described later
  )

None of these quest interactions so far have dealt with rewards for quest completion--those must be handled explicitly as well. Examples seem tedious, but functions like `add-credits`, `remove-credits`, and `add-xp` are also defined to provide the ability to give players rewards. There are also related predicates, such as `has-credits?`.

A full list of available functions is at the end of this page.

SWC Lisp offers the ability to store data (or state information) between interactions and therefore provide memory of interactions between characters and other entities. This state falls into a number of categories, each of which are handled analogously: global variables, entity variables (two types, e and o), context variables (two types, y and x), and session variables. More may be added if the need arises. Global variables are shared by all scripts, entities, and characters. They require the most care to avoid naming conflicts and are only available to admin-curated scripts. Entity variables are specific to the entity being interacted with (e type) or specific to both the entity and the character (o type), context variables specify one (y type) or two (x type) context entities to be used to do an arbitrary variable lookup, and session variables are specific to the exact conversation happening right now: they reset between conversations. Not all variables are available to all script writers--some may be restricted based on the type of entity and/or script being written.

We begin by creating a reference to a variable of the desired type. For G-, E-, S-, and O- variables, the context is implied (current entity/character/session), but for X- and Y- variables, context must be supplied in the form of an entity reference Additionally, a default value is supplied if the variable has not been used or created before:

Code
(defvar rancor-stage (get-quest 101))
; Tracks how many trophies were turned into this specific NPC
(defvar my-trophies (evar 'trophies 0))
(defvar rancor-kills (yvar 'rancor rancor-stage 0))
Important

The variable name provided to `yvar`, `evar`, etc. is quoted. This is the first significant use of quoting in SWC Lisp, and while it is a minor point it is very important (and unfortunately may lead to errors as players leave out the quote).

Later, we can retrieve how many confirmed rancor kills a player has (based on how many trophies they have turned in) in order to update quest status or inform them of progress:

Code
(defun check-rancor-stats
  (cond
    [(ge? rancor-kills 10)
      (quest-finish rancor-stage)
      (quest-start strider-stage)
      (say "Great, that's 10 rancors. Now bring me 10 kintan strider trophies!")]
    [#t (say (concat "You still need to kill " (- 10 rancor-kills) " rancors"))]))

And, of course, we need a way to manipulate variable values, which can be done using `save-var!`. Functions which change a variable's value, rather than merely declaring or using it, (called mutators) are frequently indicated by an exclamation point at the end of the function name (read out loud as bang). Several mutators exist for manipulating the state of SWC game objects beyond taking an "action" like saying something or awarding credits. We can assign a new value to a G-, E-, C-, Q-, or S- variable like so:

Code
(defvar rancor-kills (yvar 'rancor rancor-stage 0))
(save-var! rancor-kills (+ rancor-kills 1))
Important

Be aware that regular variables (created with `defvar` alone) cannot be modified with `save-var!`. Only the results of a `gvar`, `evar`, `ovar`, `svar`, `xvar`, or `yvar` expression can be modified with `save-var!`.

Note
save-var! is the new name for set-var!. The old name can still be used, but the updated name is preferred. The use of set! on a persistent var will update the variable value in code, but will not persist the value to the database. It is useful to do this for performance reasons to batch changes and only apply the change once at the end: (defvar score-counter (yvar 'counter 0)) (set! counter (+ counter 1)) (set! counter (+ counter 1)) (set! counter (+ counter 1)) (save-var! counter counter)

SWC Lisp also allows users to create reusable code modules that can be shared with others. There are multiple core SWC-curated libraries with functionality not included in the base, for example `swclib` which defines a large number of additional functions for convenience when interacting with the core library features. A module can be created by any player, edited collaboratively, and restricted by password when desired.

Modules follow the same syntax for declaration as normal NPC scripts, except they do not require the `start` symbol to be defined (and defining it has no effect). Instead, they use another primitive, `module-export` to define functions and variables to be available in the calling script. `module-export` accepts a variable number of arguments which can be symbol names or pairs which allow you to rename the symbol

Code
(defvar emperor "Palpatine")
(defvar lackey "Darth Vader")
(defun (is-emperor? c)
  (eq? (get-name c) emperor))
(defun (is-lackey? c)
  (eq? (get-name c) lackey))

(module-export
  is-emperor?
  ; is-lackey? is offensive so give it a name that seems respectful for other people to use!
  (is-dlots? is-lackey?))

In this case, after the script module is loaded, two functions, `is-emperor?` and `is-dlots?` will be available, but the internal variables and function names will not be visible to the place where the module is used.

Modules are loaded using the `load` primitive, which accepts one or two arguments. For modules without an access key, only the name is required. Otherwise, both a name and an access key are required.

Code
(load "swclib")
(load "private-lib" "p4ssw0rd")

Modules may be used by other modules modules. Only one "instance" of a module will be created, so if it maintains internal state (svars, etc.) be aware that they will be shared by all such instances. This allows for superior communication, but it can introduce complications if you are not careful with variable usage.

With this in mind, we can look at a complete set of scripts which implement one of our new player quests: talk to someone, move to another location, talk to someone else, and then get a reward for it.

The quest starts when the player talks to the first NPC, James Walker. He uses conditions to prevent the quest from being assigned multiple times and to change his responses based on the current quest status:

Code
(defvar target (get-npc 10072))
(defvar walking-tutorial (get-quest 2))

(defun start
  (cond
    [(quest-finished? walking-tutorial) (say "Sorry, I don't have any more work for you")]
    [(quest-started? walking-tutorial) (say (concat "Go talk to my brother " (get-name target) " and let him know his weapon shipment came in, please."))]
    [#t
      (say (concat "Hello there! You look like you could use some exercise. Why don't you walk over to my brother " (get-name target) " at and let him know his weapon shipment came in? You can walk by selecting the Travel button at the top of your Ground Travel page, which is linked on the right menu. Then enter your coordinates and hit Go!"))
      (add-response "Hey, who are you calling out of shape? Forget it! You can tell him yourself." decline)
      (add-response "I guess I can do that. I hope there's something in it for me." accept)]))

(defun decline
  (say "Fine. If you change your mind before someone else comes along, let me know."))

(defun accept
  (say "Great! I'm sure he'll have a tip for you.")
  (quest-start walking-tutorial))

Two variables are declared at the top to identify objects he interacts with: a quest and a "target" NPC, both of which are specified directly by ID. In this case, the target is Ryan Walker, his brother, whom we must talk to finish the quest and receive our reward. The quests are created separately (currently managed by admin tools), and the appropriate ID number should be noted to add it to the script.

Ryan also checks for quest status and tailors his response appropriately. When the player elects to turn the quest in, he marks the objective as done and gives the player a reward.

Code
(defvar walking-tutorial (get-quest 2))

(defun start
  (say "Yeah? What do you want?")
  (cond
    [(quest-started? walking-tutorial) (add-response "Um.. There's a weapon shipment for you. I don't know where it is. Or what it is. Maybe I should have gotten more information about this. I sure hope you're not up to something shady." done)]
    [#t (add-response "N..Nothing. Sorry to bother you." no-response)]))

(defun done
  (say "Really? Well it's about time! Here's something for your trouble. Listen, why don't you use this money to buy some equipment? I hear there's a guy in the Shop (at coords?) who can help you. Walk over to the Shop in this city and use the Board button on your Travel page to enter.")
  (quest-finish walking-tutorial)
  (add-xp 25 (concat "Finished quest: " (get-name walking-tutorial)))
  (add-credits 100000))

;; This shows no response from the NPC and gives the character no opportunity to react further
(defun no-response #t)

Ryan also has an empty response function, `no-response`, which is a technique that can be used when the player should get the last line in a conversation.

Not all functions or language features are available in all contexts (for example, custom NPCs cannot access quests or global variables).

Code
number : 1, 10, 0.01, -123
boolean : #t, #f
string : "This is a string"
string : """This is another way to define a string"""
symbol : symbol, another-symbol
atom : number, string, boolean, or symbol
expr : (atom1 atom2 ... atomN)
Note
Strings can be multi line.
Note
Use the triple quotes string syntax to simplify HTML. HTML is filtered prior to output the same way forum posts are.

These are special forms provided by the language for basic tasks like variable declaration, function declaration, and flow control.

Code
(defvar name value-expr)

(defun name body-expr1 body-expr2 ... body-exprN)

(cond
  [test-expr1 body-expr1 body-expr2 ... body-exprN]
  [test-expr2 body-expr1 body-expr2 ... body-exprN]
  [#t body-expr1 body-expr2 ... body-exprN])

(save-var! name value)

(let ((name1 value-expr)
      (name2 value-expr)
    ...
    (nameN value-expr))
  body-expr1
  body-expr2
  ...
  body-exprN)

(lambda (arg1 arg2 ... argN)
  body-expr1 body-expr2 ... body-exprN)

(module-export
  symbol1
  symbol2
  ...
  symbolN)

(module-export
  (export-symbol1 symbol1)
  (export-symbol2 symbol2)
  ...
  (export-symbolN symbolN))

Variables that are always available inside a script:

Code
self : A reference to the entity that the script is running on (current NPC being talked to, current item being talked to, etc.)
character : A reference to the character currently interacting with this script
empty : A list terminator required for advanced scripts

This list includes only currently implemented and available SWC-related functions. Language-builtin functions are listed separately.

Showing Unprivileged Functions. Switch to Privileged Functions.
Code
evar(string name, default)
ovar(string name, default)
svar(string name, default)
+(... args?)
-(... args?)
*(... args?)
/(a, b)
sqrt(a)
ge?(a, b)
>=(a, b)
le?(a, b)
<=(a, b)
gt?(a, b)
>(a, b)
lt?(a, b)
<(a, b)
and(... args?)
or(... args?)
not(a)
floor(int|float num): float
ceil(int|float num): float
round(int|float num, int precision?, int mode?): float
log(float num, float base?): float
exp(float num): float
modulo(a, b)
stochastic_round(float)
concat(... args?)
strlen(string string): int
trim(string string, string characters?): string
substr(string string, int offset, ?int length?): string
stripos(string haystack, string needle, int offset?): int|false
str_contains(string haystack, string needle): bool
str_starts_with(string haystack, string needle): bool
str_ends_with(string haystack, string needle): bool
strtolower(string string): string
strtoupper(string string): string
lcfirst(string string): string
ucfirst(string string): string
padleft(input, len, str?)
padright(input, len, str?)
numeric?(mixed value): bool
hex-string?(string input): bool
string?(mixed value): bool
bool?(mixed value): bool
entity?(a)
nf(float num, int decimals?, ?string decimal_separator?, ?string thousands_separator?): string
number_format(float num, int decimals?, ?string decimal_separator?, ?string thousands_separator?): string
htmlentities(string s)
fmt(Script\Environment env, string fmt)
length(list): int
reverse(array array, bool preserve_keys?): List
explode(string separator, string string, int limit?): List
join(string separator, array): string
natural-join(array, string glue?, string conjunction?): string
list-search(needle, array haystack, bool strict?)
sublist(?array array, int offset, ?int length?, bool preserve_keys?)
sort(list)
nth-of(list, int n)
rand(int min?, int max?): int
rand-from-list(a)
assert(assertion, string msg?)
get-admin()
get-class(EntityType e)
get-entity-type-id(string name)
get-type(Entity e)
get-type-type(int typeID, int entityType)
get-type-of(entity)
get-entity-type-name(Entity e)
get-entity(id, entityType)
get-id(Entity e)
get-name(Named obj)
get-formal(obj)
get-race(obj)
get-gender(obj)
get-character(name)
get-infofield(obj)
get-infofield2(Character c)
get-infofield3(Character c)
get-facility-type(int type)
get-faction(name)
is-freelancer?(Character c)
faction-owned?(Asset e)
get-entity-faction(Entity e)
faction-type(Faction f)
faction-leader(Faction f)
faction-website(Faction f)
get-npc(id)
get-npc-owner()
get-npc-type(int type)
get-hostile-owner()
get-market-owner()
is-guard?(NPC npc)
get-item(id)
get-item-type(int type)
is-container?(Item item)
holding-item?(Entity entity, ItemType itemType, ?int itemID?)
get-equipped-items(Entity entity)
pick-up-item(int typeID, ?int slot?, ?int containerID?, ?int itemID?, bool checkCapacity?)
get-ship(id)
get-ship-type(int type)
get-vehicle(id)
get-vehicle-type(int type)
get-creature(id)
get-creature-type(int type)
get-droid(id)
get-droid-type(int type)
get-station(id)
get-station-type(int type)
get-room(id, container?)
get-room-type(Entity entity)
in-room?(entity)
get-door-between-rooms(int roomAID, int roomBID, ?Entity container?)
get-room-direction(Room roomA, Room roomB)
get-type-main-image(EntityType entityType)
get-main-image(Entity entityType)
get-hp-status-text(Entity entity)
get-hp(Entity entity)
get-hp-max(Entity entity)
get-hull(Entity entity)
get-hull-max(Entity entity)
get-passenger-count(Entity entity)
get-weight-available(Entity entity)
get-volume-available(Entity entity)
get-container(Entity e)
get-top-container(Entity e)
get-owner(Asset e)
get-commander(Asset e)
get-pilot(Asset e)
is-owner?()
is-commander?()
is-manager?()
is-pilot?()
is-supervisor?()
is-ally?(Entity test)
is-neutral?(Entity test)
is-enemy?(Entity test)
is-traveling?(Entity e)
get-destination(Entity e)
get-eta(Entity e)
get-location(Entity e)
get-surface-location(Positioned entity)
get-travel-layer(Positioned entity)
get-terrain-name(Planet planet, Point loc)
get-current-planet()
planet-name(Entity e)
get-planet-size(Planet planet)
get-homeworld(Race race)
city-name(Entity e)
system-name(Entity e)
sector-name(Entity e)
door-locked(Door door)
get-door-type(Door door)
can-travel-through-door(Door door, Entity entity)
lock-door(Door door, Entity entity)
unlock-door(Door door, Entity entity)
get-medical-timer(Entity target)
send-message(Entity sender, Entity recipient, string message)
flash(string type, string msg, ?string id?)
time-until(int seconds): string
time-until-brief(int seconds): string
time-until-cgt(int cgt): string
time-until-cgt-brief(int cgt): string

Functions available as part of the language that do useful programming-related things. These might be more useful in more sophisticated scripts. Currently these are of limited use as our library functions don't create data that needs to be manipulated in this way.

Code
(car list)
(cdr list)
(cons expr1 expr2)
(list expr1 expr2 ... exprN)
(empty? list)
(eq? atom1 atom2)
Code
; Pretty print expressions in debugger
(dbg-pp expr1 expr2 ... exprN)

; Raw print expressions in debugger
(dbg-rp expr)

; Break in debugger when executed
(dbg-break)

; Print entire environment (defined functions and variables)
(dbg-env)

; Print environment (defined variables only)
(dbg-env-vars)