Difference between revisions of "SWC LISP"

From Star Wars Combine :: Game Guide
Jump to: navigation, search
(Conditional Statements)
(Conversational Functions)
Line 483: Line 483:
 
! Notes
 
! Notes
 
|-
 
|-
|say||message &close||Output: NPC "says" message.  ''&close'' is boolean.  If true, this will start a new paragraph.|| || ||
+
|say||message &close||Output: NPC "says" message.  ''&close'' is boolean (defaults to true).  If true, this will start a new paragraph.|| || ||
 
|-
 
|-
|describe||message &close||Output: NPC "describes" message.  &close is boolean.  If true, this will start a new paragraph.|| || ||
+
|describe||message &close||Output: NPC "describes" message.  ''&close'' is boolean (defaults to true).  If true, this will start a new paragraph.|| || ||
 
|-
 
|-
|ooc||message &close||Output: NPC "oocs" message.  &close is boolean.  If true, this will start a new paragraph.|| || ||
+
|ooc||message &close||Output: NPC "oocs" message.  ''&close'' is boolean (defaults to true).  If true, this will start a new paragraph.|| || ||
 
|-
 
|-
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting|| || ||
+
|say-c||message ||Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || ||
 
|-
 
|-
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting|| || ||
+
|describe-c||message||Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || ||
 
|-
 
|-
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting|| || ||
+
|ooc-c||message ||Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks || || ||
 
|-
 
|-
 
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function.  NOTE: Currently the callback functions may not have any parameters.|| || ||
 
|add-response||message callback ||Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function.  NOTE: Currently the callback functions may not have any parameters.|| || ||
Line 499: Line 499:
 
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function.  NOTE: Currently the callback functions may not have any parameters. || || ||
 
|add-action||message callback||Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function.  NOTE: Currently the callback functions may not have any parameters. || || ||
 
|-
 
|-
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function.  NOTE: Currently the callback functions may not have any parameters. || || ||
+
|add-text||message callback||Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function.  NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective || || ||
 
|-
 
|-
 
|add-input||not implemented||Input: creates a text box for the user to type something in.  In progress. || || ||
 
|add-input||not implemented||Input: creates a text box for the user to type something in.  In progress. || || ||
 +
|-
 +
|clear-window|| ||Clears the current conversation log window before rendering the information from the current interaction || || ||
 
|-
 
|-
 
|}
 
|}

Revision as of 18:16, 14 September 2018

Main page - trying to reorganise the LISP content


SWC-LISP can be considered a fork from the main Lisp branches that is used to interact with the Combine's database. For this reason it is not used to create stand-alone applications, rather dialogue scripts for Custom NPCs or working procedures for objects as well as implementing game-wide quests.

Definitions

Notation for a sequence of things is often 1 2 ... n, where the first couple things give you an idea of how the sequence goes (in this case incrementing by 1), the ellipses (...) indicate it continues. When referring to any specific 'thing' in that sequence, we talk about its position. 1 is the first thing. 2 is the second thing, and all the way at the end, the term n representing the last thing in that sequence is the "nth" thing. We use the same kind of notation and terms to discuss lists.

atom 
a single 'thing' - the smallest unit thing in LISP. It is an s-expression, but more than that it is a value, number,
boolean 
Boolean is a data type that can be either True or False. We often refer to functions which return #t or #f as predicates, and in SWC-LISP, the convention is to name those functions ending with a question mark. If i made a predicate to check if numbers a and b are both 2, i'd name it both-two?
define 
in the sense of LISP, this means to formally tell the script what you want a given symbol to evaluate to. You use two functions for this: defvar for variables and defun for functions.
element 
We often refer to each 'thing' inside a list as an element. It's useful to have a term for this since we discuss how lists are navigated and need common ways to talk about it.
evaluate 
More or less this means 'determine the meaning of '. This action is what the LISP interpreter does for every s-expression. We often say an s-expression 'evaluates to' something else, and many LISP books use the notation => to indicate that. E.G. 1=> 1; (defvar blue "Red") blue=> "Red"; (+ 1 7) => 8; (concatenate "My favourite colour is " blue) => "My favourite colour is Red"
functions 
Instructions to the interpreter on what to do. You define these using defun telling the interpreter a) what you want the symbol to be, b) if you want to feed your function data (parameters), what temporary symbols you will use to refer to each parameter ("local variables"), and what function that symbol should evaluate to. More on this later, but the important concept is that functions are your way of directing what you want to happen, when.
lambda functions 
They are (generally) function definitions not bound to an identifier - or in our case a symbol. They can be used anywhere you'd normally use a defined function name by directly describing its behavior rather than indirectly by referring to the name of an established function (Excepting add-action, add-response, add-text). I primarily use them in more interesting ways than the above in order to create temporary functions based on a template. In general, they are a way of defining a function for use in an s-expression without having to name the function. You can think of it as the function equivalent of passing a string value as "Blue" instead of (defvar colour "Blue") colour.
list 
a group of s-expressions represented in the form (s-expression1 s-expression2 ... s-expressionN). A list is itself an s-expression, so can be contained inside other lists.
parameter 
a piece of data you feed to a function, upon which it operates. Also known as input. These are often listed as an expected type - for example defvar expects a symbol and a value, while say expects a string.
quoting 
Lisp must decide which parts of our program consist of code (stuff to be executed) and which parts are just data. Whenever you type something, Lisp assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to code mode. On the other hand, stuff written in data mode is treated as data. This means the computer will not try to "execute" it, which allows us to have information in our code that’s just plain old data. The single quote ' tells Lisp to treat the subsequent form as a chunk of data — simply a list of items. Lisp then prints the result of evaluating what we entered, which is the list itself. It ignores any functions or variables in our list, treating everything as data. Example: (+ 2 3) => 5 whereas '(+ 2 3) => (+ 2 3).
quasiquoting 
This feature allows us to create chunks of data that have small pieces of Lisp code embedded in them. To enable quasiquoting, you must use a backquote [`] not a single quote ['] when switching from code to data mode. Both the single quote and backquote in Lisp "flip" a piece of code into data mode, but only a backquote can also be unquoted using the comma character, to flip back into code mode. Example: `(a b ,character) produces a list that contains the symbols a and b, followed by the value of the symbol character. The first two are not evaluated, but the third is.
s-expression 
a general term that means an atom or a grouping of atoms called a list.
scope 
Really we mean lexical scope, which sets the range of functionality of a symbol so it can only be used inside the part of the script it is defined in. This is a longer subject and will be covered in more detail later, but when we talk about scope, we're talking about where we can use a particular defined symbol and where we cannot.
session 
a unique interaction between a character and a scripted entity. Lasts as long as the script is still running.
string 
A set of letters and numbers that the interpreter does not evaluate further - treats it as text. "Blue" is a string, while Blue is a symbol. (defvar colour "Blue") defines the symbol `colour` to evaluate to the string "Blue". You can also feed defvar (or other functions) a symbol which evaluates to the expected type. (defvar some-colour colour) would then set the symbol `some-colour` to evaluate to the symbol `colour`, which evaluates to the string "Blue".
symbol 
looks just like any other word in the code. It's exactly what you intuit it to mean: a representation of something else - a value, a string, a function, a list, etc.
variables 
As a programming term, it is a storage location paired with a symbolic name. For our purposes, it's a symbol that will evaluate to a set "something" stored: a value, another symbol, a function, etc.). (defvar symbol value) is the general form, and that makes an unchangeable variable, which you can then refer to as `symbol` for the rest of the script. There are exceptions/provisos/caveats, but they'll be discussed as they come up.

Variables

  • *vars can now properly handle lists of values in addition to scalar values. Storing an instance of a class is not supported and (should) result in an exception being thrown.

Predicates

The following table lists functions that return either #t or #f.

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
is-unharmed? player-NPC-object Returns true if player-NPC-object's HP-Status-Text is "unharmed" (is-unharmed? character) #t (load "swclib")
is-slightly-wounded? player-NPC-object Returns true if player-NPC-object's HP-Status-Text is "slightly wounded" (is-slightly-wounded? character) #f (load "swclib")
is-wounded? player-NPC-object Returns true if player-NPC-object's HP-Status-Text is "wounded" (is-wounded? character) #f (load "swclib")
is-badly-wounded? player-NPC-object Returns true if player-NPC-object's HP-Status-Text is "badly wounded" (is-badly-wounded? character) #f (load "swclib")
in-same-faction? entityA entityB Returns true if entity A and B are in or owned by the same faction. Can be written (eq? (get-entity-faction entityA)(get-entity-faction entityB)) (in-same-faction? ) #t (load "swclib")
in-container? object container Returns true if object is inside container (n-container? hilt toolkit) #t (load "swclib")
is-ally? player-NPC-object Returns true if NPC/PC is IFF friendly (defaults to self) (is-ally? self) #t
is-enemy? player-NPC-object Returns true if NPC/PC is IFF enemy (defaults to self) (is-enemy? self) #f
is-neutral? player-NPC-object Returns true if NPC/PC is IFF neutral (defaults to self) (is-neutral? self) #f
is-owner? player Returns true if character is the owner of the NPC (is-owner? character) #t
is-commander? player Returns true if character is the commander of the NPC (is-manager? character) #t
is-manager? player Returns true if character is the manager of the NPC (is-manager? character) #t
is-pilot? player Returns true if character is the owner of the NPC (is-pilot? character) #t
is-supervisor? player Returns true if character is the supervisor of the NPC (is-supervisor?) #t
is-freelancer? player Returns true if the character is a freelancer (is-freelancer? character) #t
is-traveling? player Checks if the character is traveling or not (is-traveling? character) #t
in-room? entity-object Checks if the entity is in any room at all, as opposed to outside on the surface (in-room? entity-object) #t
faction-owned? entity Returns true if the entity is owned by a faction (faction-owned? self) #t
empty? list checks if you have an empty list. Can have unexpected behaviour if attempting to store an empty list in a persistent variable. 1. (empty? `())
2. (empty? `(1))
1. #t
2. #f
in? needle haystack Returns true if one or more of the elements of haystack is equal to needle. needle is an atom and haystack is a list of atoms (in? 3 (list 1 'a 6 3 'u)) #t (load "funlib")
sublists-empty? list-of-lists Returns true if any of the sublists are empty. Note: the function expects only lists, no atoms at the top level (load "funlib")
earlier? timeA timeB Returns true if timeA is less than timeB. timeA and timeB are two time objects (load "timelib")
later? timeA timeB Returns true if timeA is greater than timeB. timeA and timeB are two time objects (load "timelib")
same-time? timeA timeB Returns true if timeA is equal to timeB. timeA and timeB are two time objects (load "timelib")
enum-valid? Tests a value for being part of an enum

Operators

Arithmetic Operators

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
+ number1 number2 &numberN Adds numbers together (+ 5 2) 7
- number1 number2 &numberN Subtracts numbers (- 5 2) 3
* number1 number2 &numberN Multiplies numbers (* 5 2) 10
/ number1 number2 Divides numbers (/ 10 2) 5
abs number Returns the absolute value of number (abs -10) 10 (load "mathematics")
power number exponent Returns the value of numberexponent (power 2 3) 8 (load "mathematics")
minof list-of-numbers Returns the minimum value from a list of numbers (minof '(2 3 7 9 1 18)) 1 (load "mathematics")
maxof list-of-numbers Returns the maximum value from a list of numbers (maxof '(2 3 27 9 1 18)) 27 (load "mathematics")
neg? number Returns true if number is negative, nil if positive (neg? -1) #t (load "mathematics")
pos? number Returns true if number is positive, nil if negative (pos? 1) #t (load "mathematics")
zero? number Returns true if number is 0, nil if otherwise (zero? 0) #t (load "mathematics")
factorial number Returns !number (factorial 5) 120 (load "mathematics")
common-number-format number Returns a string with commas separating the thousands (common-number-format 10000.51) "10,000.51" (load "mathematics")
add-leading-zeros number &HowManyDigits Returns a string of value = number, with optional integer HowManyDigits leading zeros. HowManyDigits defaults to 1 1. (add-leading-zeros 3)
2. (add-leading-zeros 30)
3. (add-leading-zeros 3 2)
4. (add-leading-zeros 30 2)
1. "03"
2. "30"
3. "003"
4. "030"
(load "mathematics")

Comparison Operators

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
ge? number1 number2 Is number1 equal to or greater than number2? (ge? 5 2) #t
le? number1 number2 Is number1 equal to or less than number2? (le? 5 2) #f
gt? number1 number2 Is number1 greater than number2? (gt? 5 2) #t
lt? number1 number2 Is number1 less than number2? (lt? 5 2) #f
eq? atom1 atom2 Returns true if the two provided atoms are equal. Does not work for Lists. 1. (eq? 1 1)
2. (eq? 1 2)
1. #t
2. #f
neq? atom1 atom2 Returns true if atom 1 is not equal to atom 2 (neq? 1 2) #t (load "funlib")
eq-lists? listA listB Returns true if all elements of list A are equal to all elements of list B. As of Y19D290 it doesn't take into account lists of lists, but only one-dimensional lists 1. (eq-lists? '(a b c) '(d e f))
2. (eq-lists? '(a b c) '(a b c))
3. (eq-lists? '( '(a) b c))
1. #f
2. #f
3. Error
(load "funlib")

Logic Operators

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
and boolean-expression1 boolean-expression2 &boolean-expressionN Returns true if all exprs are true (and? #t #f) #f
or boolean-expression1 boolean-expression2 &boolean-expressionN Returns true if at least one expr is true (or #t #f) #t
not boolean-expression1 boolean-expression2 &boolean-expressionN Returns the opposite value (not #t) #f

Getters

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
get-name player-NPC-object Returns the name of the entity 1. (get-name self)
2. (get-name (get-entity-faction character))
3. (get-name (get-container self))
4. (get-name (get-vehicle 1150488))
1. Johnny Walker
2. New Republic (empty string if Freelance
3. Tydirium (Current container name, e.g. the ship or vehicle standing in)
4. My vehicle
get-race player-NPC Returns the PC/NPC's race as string (get-race self) Nautolan
get-infofield player-NPC Returns the string of the first infofield of PC/NPC's 1. (get-infofield self)
2. (get-infofield (get-npc 111548))
1. Master Carpenter
2. empty string
get-infofield2 player-NPC Returns the string of the 2nd infofield of PC/NPC's 1. (get-infofield2 self)
2. (get-infofield2 (get-character "Kay Dallben"))
1. O-4
2.
get-infofield3 player-NPC Returns the string of the 3rd infofield of PC/NPC's 1. (get-infofield3 self)
2. (get-infofield3 (get-character "Kay Dallben"))
1. Inactive
2.
get-gender player-NPC Returns the PC/NPC's gender as a string (get-gender self) Male
get-formal player-NPC Returns the PC/NPC's formal greeting (Sir if gender is male, Ma'am if gender is female.) (get-formal (get-character "Kay Dallben")) Sir
get-entity-faction player-NPC Returns the PC/NPC's current faction (get-entity-faction character) Galactic Empire
get-destination entity Returns the destination name (get-destination entity) "Corellia sector" (if deep space)
"Corellia system" (if heading to that system)

"Corellia planet" (if heading in sublight)
"Atmosphere (3,4) of Corellia" (if heading in atmo)
"Ground (3,4) of city Cityname on Corellia" (if heading to ground in city)
"Ground (3,4) at (4,7) on Corellia" (if heading to ground outside a city)

get-eta entity Returns the ETA for current travel (get-eta entity) 3 days, 24 hours and 5 minutes
get-entity-type-name entity Returns the name of the type of the entity (get-entity-type-name (get-container self)) Lambda Shuttle
get-type entity-object Returns the current container entity type, e.g. the ship, vehicle, city, planet, station (get-type entity-object) Ship, Vehicle, City, Planet, Space Station
get-entity-type-id name Type ID for the entity type name. {Ship, Vehicle, City, Planet, Space Station} (get-entity-type-id 'Planet) -> n/a
get-type-type typeID entityType returns a full TYPE (get-type-type 298 (enum "EntityType" "ITEM")) is equal to (get-item-type 298)
get-creature-type typeID returns the type of Creature (get-creature-type 175) returns the type for an Eye-Snatcher
get-droid-type typeID returns the type of Droid (get-droid-type 14) gets the droid type obj for Pit Droids
get-item-type typeID returns the type of Item (get-item-type 298) returns the type of a Focusing Crystal
get-npc-type typeID returns the type of NPC (get-npc-type NUM) returns the type for a NPC of typeid NUM needs testing
get-type-of entity returns the type object for the entity (get-type-of self) could return the type for a Quest NPC (if self is a quest npc)
get-npc-owner returns the "NPC Owner" object useful for an is-unclaimed? check.
get-hostile-owner returns the "Hostile Owner" object ie checks if it is a spawned Bandit/Creature
get-market-owner returns the "Market Owner" object
get-character name entity-object for character "name" (get-character "Kay Dallben") n/a
get-faction name faction-object for faction "name" (get-faction "Darkness") n/a
get-npc id npc-object for NPC with ID id (get-npc 155408) n/a
get-quest id quest-object for quest with ID id (get-quest 4408) n/a
get-item id item-object for item with ID id (get-item 481099) n/a
get-ship id ship-object for ship with ID id (get-ship 448088) n/a
get-vehicle id vehicle-object for vehicle with ID id (get-vehicle 46846816) n/a
get-room id room object for room ID. Rooms are commonly numbered among ALL of a given entity type. So all VSDs have the same room numbers, and no other entity has those room numbers. (get-room 4478) n/a
get-id entity ID for the entity (get-id (get-npc 100)) -> 100 n/a
get-hp-status-text entity string of the hp-status-text {unharmed, slightly-wounded, etc.} (get-hp-status-text self) n/a
get-owner entity owner object of entity (get-owner self)-> Kay Dallben
get-container entity entity-object for container of entity. (get-container self) n/a
get-location entity String of location (currently including hyperlinks) if viewable without godmoding. needs testing
get-storageform entity get-entity-type-name Returns a storageform for the entity. As of Y19D290 it works only on entities of types: NPC, Item, Ship, Room, Vehicle, Character (missing entities: Quest, Hook, Faction, Facility, Station, Droid).
NOTE: If you use this in a script module you must bind the function (get-entity-type-name)
(get-storageform (get-npc 22048668) get-entity-type-name) '("NPC" "Quest NPC" 22048668 "Vash Thompson") (load "swclib")
get-entity-from-storageform storageform Returns the entity object described in storageform. storageform is a list in the form of '("NPC" "Quest NPC" 22048668 "Vash Thompson") (load "swclib")
get-first-n n list Returns the first n elements of list. If n > (length list) it returns the whole list. n is an integer and list is a list (get-first-n 3 '(a b c d e f g h i j)) '(a b c) (load "funlib")
get-name-typeof entity-type Returns just the Name component of the entity-type. entity-type is a type, i.e. what you can get from (get-typeof entity) (defvar held-in-hand (get-item FocusingCrystalid))
(get-name-typeof (get-typeof held-in-hand))
"Focusing Crystal" (load "funlib")
get-nth haystack nth Returns the nth element of haystack using car and cdr only. This does not call the PHP nth-of, so it can return a symbol. It might have performance issues for large lists or large nth (get-nth ?? ?? (load "funlib")

Functions for SWC Database

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
faction-type player-NPC Character's faction's type (faction-type (get-entity-faction character)) Mining (Empty string if freelance)
faction-leader player-NPC Character's faction's leaders name (faction-leader (get-entity-faction character)) Ellias (Empty String if freelance)
faction-website player-NPC Character's faction's website URL (faction-website (get-entity-faction character)) http://swcombine.com (Link) (Empty string if freelance)
city-name player-NPC Current city name (city-name character) City 327
planet-name player-NPC Current planet name (planet-name character) Glee Anselm
system-name player-NPC Current system name (system-name character) Danju
sector-name player-NPC Current sector name (sector-name character) Tapani

Time Related Functions

Functions that are useful in the tracking and manipulation of Time objects. Time objects are lists in the form of '(Y D H M S).

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
cgt-year n.a. Gets current CGT year (cgt-year) 12
cgt-day n.a. Gets current CGT day (cgt-day) 183
cgt-hour n.a. Gets current CGT hour (cgt-hour) 23
cgt-minute n.a. Gets current CGT minutes (cgt-minute) 59
cgt-second n.a. Gets current CGT seconds (cgt-second) 59
timeofday n.a. Gets current phase of day (timeofday) Morning, Afternoon, Evening
now-time n.a. Returns the 'time' object for Now (now-time) (load "timelib")
now-seconds n.a. Returns the seconds for Now (now-seconds) (load "timelib")
now-plus-days amount Add amount to Now in days (now-plus-days 3) a time object that is 3 days from Now (load "timelib")
now-plus-hours amount Add amount to Now in hours (now-plus-hours 5) a time object that is 5 hours from Now (load "timelib")
now-plus-minutes amount Add amount to Now in minutes (now-plus-minutes 18) a time object that is 18 minutes from Now (load "timelib")
now-plus-seconds amount Add amount to Now in seconds (now-plus-seconds 55) a time object that is 55 seconds from Now (load "timelib")
timer-end-time amount-or-time &ydhms start-time Returns a time object that marks the end of a timer of length amount-or-time beginning on start-time. The ydhms defaults to 'm (minutes) and can be 'y 'd 'h 'm 's to indicate what units amount-or-time is in. start-time defaults to now-time but is a time object to denote the start time of the timer. 1. (timer-end-time 30)
2. (timer-end-time 5 'h '(17 192 13 57 05))
1. a time object that is 30 minutes from Now (the same as (now-plus-minutes 30) i.e. 30 minutes from CGT at the time of script execution
2. '(17 192 18 57 05) i.e. 5 hours from Y17 D192 at 13:57:05 being Y17D192 18:57:05
(load "timelib")
time-to-string time &format Converts a time object to a string. format defaults to 'YDHMS If time '(17 192 18 20 15) then:
1. (time-to-string time 'YDHMS)
2. (time-to-string time 'YYDDHHMMSS)
3. (time-to-string time 'YsDsHsMsSs)
1. "Y17 D192 18:20:15"
2. "Year 17 Day 192 18:20:15"
3. "Years: 17 Days: 192 Hours: 18 Minutes: 20 Seconds: 15"
(load "timelib")
cmp-time timeA timeB Basic comparison of two time objects. Returns true if equal (cmp-time) (load "timelib")
fix-improper-time time Corrects an improper time object. "Improper" refers only to D, H, M, S being out of bounds.
-60 < M < 60; -60 < S < 60; -23 < H < 23; -365 < D < 365
(load "timelib")
add-n time amount Adds that amount of n to the time. n is any of seconds mins hrs days years (load "timelib")
add-times timeA timeB Returns the time object which is the sum of timeA and timesB. Proper format. (load "timelib")
add-ydhms-to time ydhms amount All-encompassing time-addition function. Adds amount 'y 'd 'h 'm or 's to time. You can also use 0, 1, 2, 3 or 4 to refer to year, day, hour, minutes or seconds respectively, for ydhms (load "timelib")
sub-times timeA timeB Returns the time object which is timeA minus timesB (load "timelib")
diff-times timeA timeB Returns the time object which is the smalles difference of timeA and timeB (load "timelib")
to-seconds time Converts time into seconds (load "timelib")
to-time seconds Converts seconds into time (load "timelib")

Strings

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
abc n.a. List of strings comprising the alphabet, lowercase (load "swclib")
ABC n.a. List of strings comprising the alphabet, uppercase (load "swclib")
numstr n.a. List of strings from 1 to 9, rather than numbers (load "swclib")
aurebesh-caps n.a. List of strings comprising the Aurebesh alphabet, with the initial letter capitalised "Aurek" "Besh" ... (load "swclib")
aurebesh-lc n.a. List of strings comprising the Aurebesh alphabet, all lowercase "aurek" "besh" ... (load "swclib")
trim ?? ??
flash type message Shows a flashing message to the player to provide non-conventional extra information, for example to indicate that a journal entry was added. type is one of: 'good 'bad 'info, message is a string (flash 'good "You have received 25 XP for helping to free the Jawas"
enum Retrieves a named value from a specific enum (enum 'entityType 'room) Retrieves the entity type value for rooms
enum-values Retrieves all values from an enum
substr string start &length Carves out a portion of a string. start is the position of the first character in the string you want to get, and length is the number of characters you want (default is to the end of the string). Positions begin at 0 for the first character. You can also use a negative number to indicate you want to start "that many" characters from the end of the string 1. (substr "I like cheese" 2)
2. (substr "I like cheese" 0 6)
3. (substr "I like cheese" -6)
1. "like cheese"
2. "I like"
3. "cheese"
strpos string find start Looks in string for the string find starting to look at position start, and returns the position in string where it finds it 1. (strpos "I like cheese" "like")
2. (strpos "I like cheese" " ")
3. (strpos "I like cheese" " " 2)
1. 2
2. 1
3. 6 (looking for a space but beginning after the first space)

Lists

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
join separator-character list Combines the elements of list with the separator-character to form a string (join ", " (list "Green" "Blue" "Yellow")) "Green, Blue, Yellow, " (load "funlib")
map function list Calls function for each member of list and returns the list of results (map (lambda (x) (+ x 2)) (list 1 0 4)) (3 2 6) (load "funlib")
apply-foreach function list Calls function once for each member in list, using the element as the single parameter. Returns #f (i.e., does not return a list of results) (apply-foreach (lambda (x) (say (x)) (list "I like" "cheesy poofs." "Do you?")) I like
cheesy poofs.
Do you?
(load "funlib")
append list element Adds element to the end of list (append (list 1 2) 3) (1 2 3) (load "funlib")
list-append list1 list-to-append Adds all the elements of the list list-to-append to the end of list1 (list-append '(1 2) '(3 4)) '(1 2 3 4) (load "funlib")
reduce function init list Reduces a list to a single value, using the combiner function provided, which function takes two inputs init and (car list) (reduce (lambda (x y) (+ x (* 2 y))) 0 (list 1 2 3)) 12 [i.e. (((0 + 2*1) + (2*2)) + (2*3)) ] (load "funlib")
repeat-fn function num-times object Repeats function for the number of num-times on object (repeat-fn (lambda (x) (+ x 1)) 4 0) 4 (load "funlib")
rand-from-list-unique n list Returns a list of n elements taken randomly from list, without any duplicates, even if an element appears multiple times in list. n is an integer and list is a list. Note that currently this returns a list of strings if the element chosen is a symbol, due to PHP (rand-from-list-unique 7 '(a b c d a a q)) '("c" "d" "a" "b" "q") (load "funlib")
find-first-of vals list-to-search (matchfun? eq?) Returns a list of the first value in vals found in list-to-search and the first position (integer with 0 = first element) in list-to-search where vals is found. vals is an atom or a list of atoms to look for in list-to-search (find-first-of (list 0 2 5) (list 1 3 2 7 5 0)) (list 2 2) (load "funlib")
find-in atom list-to-search (start-position -1) (matchfun? eq?) Returns the first position (integer with 0 = first element) where atom is found in list-to-search (find-in 7 (list 3 6 1 7 3 9 7)) 3 (load "funlib")
zip list1 list2 Returns a list of pairs of the corresponding elements of list1 and list2. list1 and list2 must be lists of atoms of equal length (zip '(1 2 3 4) '(a b c d)) '((1 a) (2 b) (3 c) (4 d)) (load "funlib")
without needle haystack Returns a list equal to haystack with all occurrences of needle removed. haystack is a list of atoms and needle is an atom (without "blue" (list "red" "yellow" "blue" "orange" "blue" "white")) (list "red" "yellow" "orange" "white") (load "funlib")
l-to-csv my-list Returns a csv-concatenated list of the elements of my-list. my-list is a list of atoms which are convertible to strings (l-to-csv '(1 b a 3 d c)) '("1,b,a,3,d,c") (load "funlib")
replace-nth my-list n value Returns a list which is a copy of my-list with the nth value changed. my-list is a list, n is an integer, value is a s-expression. Note: the first element of a list is 0. (replace-nth '(a b c d e f g) 3 "Hornswaggle") '( a b c "Hornswaggle" e f g) (load "funlib")
matchup val searchlist fetchlist Finds the position of the first occurrence of val in searchlist, and returns the same position element of fetchlist. val is a value to search for, searchlist is a list to search in, and fetchlist is the list from which to return the corresponding element. Note: this returns a string instead of a symbol if the corresponding element of fetchlist is a symbol (matchup "b" '("a" "b" "c" "d")) '("A monkey" "An eagle" "A lion" "A snake")) "An eagle" (load "funlib")
remove-first needle haystack Returns haystack without the first occurrence of needle located in it. needle is an atom, haystack is a list (remove-first x '(1 2 4 x f x 4)) '(1 2 4 f x 4) (load "funlib")
remove-nth-of haystack nth Returns haystack without the nth element. haystack is a list, nth is an integer. Note: the first element of a list is the 0th element (remove-nth-of '(1 2 4 x f x 4) 3) '(1 2 4 f x 4) (load "funlib")
ziplets list-of-lists Returns a list of n-lets made up of the corresponding elements of each list in list-of-lists. list-of-lists is a list of lists of atoms (ziplets (list (list "I" "You" "We all") (list "scream" "scream" "scream") (list "for ice cream" "for ice cream" "for ice cream"))) (("I" "scream" "for ice cream") ("You" "scream" "for ice cream") ("We all" "scream" "for ice cream")) (load "funlib")
sublist-firstof list-of-lists Returns a list of the car of each sublist (load "funlib")
rand-from-list
sort Numerical sorting of lists
length Returns the length of a list
nth-of Returns the nth element of a list
sublist Returns some number of elements from the middle of a list
reverse Reverses the elements in a list (at the top level)

Conditional Statements

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
case val caselist &compfun val is the value to check against; each case in caselist which is a list of case lists in the form `(checkval ,toDo); &compfun is an optional function which takes 2 parameters and outputs #t or #f. Default is eq?. Note: eq? doesn't work on lists, so only use atoms for the checkval. It is also possible to write a case type in longer form, as follows: (list (list "blue" (set-var! x "blue")) (list "yellow" (set-var! y "yellow"))) `(("blue" ,(set-var! x "blue")) ("yellow" ,(set-var! y "yellow"))) (load "funlib")
cond [test result] test is a s-expression that evaluates to #t or #f, result is a s-expression to execute if true (cond
[is-owner? (say "Hi, Boss!")]
[#t (say "Hello World!")])

Others

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
create-hook Creates a hook that listen to specific in-game events and then call a lisp function
get-hook Retrieves a hook by ID
delete-hook Deletes an existing hook

Conversational Functions

Function Name Required &Optional ("&") Parameters Description Example Text Example Evaluation Notes
say message &close Output: NPC "says" message. &close is boolean (defaults to true). If true, this will start a new paragraph.
describe message &close Output: NPC "describes" message. &close is boolean (defaults to true). If true, this will start a new paragraph.
ooc message &close Output: NPC "oocs" message. &close is boolean (defaults to true). If true, this will start a new paragraph.
say-c message Output: NPC "says" message, continuing previous paragraph and using that formatting, without inserting linebreaks
describe-c message Output: NPC "describes" message, continuing previous paragraph and using that formatting, without inserting linebreaks
ooc-c message Output: NPC "oocs" message, continuing previous paragraph and using that formatting, without inserting linebreaks
add-response message callback Input: Adds a clickable option labelled 'message' that will a) display "You say " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.
add-action message callback Input: Adds a clickable option labelled 'message' that will a) display "You " message; and b) run the callback function. NOTE: Currently the callback functions may not have any parameters.
add-text message callback Input: Adds a clickable option labelled 'message' that will not display anything and simply run the callback function. NOTE: Currently the callback functions may not have any parameters. Useful for multi-step decision trees, options menus, etc. that may not need to print something from the player's perspective
add-input not implemented Input: creates a text box for the user to type something in. In progress.
clear-window Clears the current conversation log window before rendering the information from the current interaction