Difference between revisions of "SWC LISP/Modules"

From Star Wars Combine :: Game Guide
Jump to: navigation, search
(swclib)
(funlib)
Line 11: Line 11:
 
(load "funlib")
 
(load "funlib")
  
<b>join</b> <i>separatorCharacter list</i>
+
Contact: Selatos, Kay Dallben
- Combine the elements of <i>list</i> with the <i>separatorCharacter</i> to form a string
 
EG: (join ", " (list "Green" "Blue" "Yellow")) -> "Green, Blue, Yellow,"
 
 
 
<b>map</b> <i>function list</i>
 
- Call <i>function</i> for each member of <i>list</i> and return the list of results.
 
E.g. (map (lambda (x) (+ x 2)) (list 1 0 4) ) -> (3 2 7)
 
 
 
<b>apply-foreach</b> <i>function list</i>
 
- Call <i>function</i> for each member of <i>list</i> but do not return results.
 
e.g. (apply-foreach (lamda (x) (say x)) (list "I like" "cheesy poofs." "Do you?"))
 
->
 
I like
 
cheesy poofs.
 
Do you?
 
 
 
<b>append</b> <i>list element</i>
 
- adds <i>element</i> to the end of <i>list</i>
 
e.g. (append (list 1 2) 3) -> (1 2 3)
 
 
 
<b>reduce</b> <i>function init list</i>
 
- reduce a <i>list</i> to a single value, using the combiner <i>function</i> provided, which <i>function</i> takes two inputs <i>init</i> and <i>(car list)</i>
 
e.g. (reduce (lamda (x y) (+ x (* 2 y))) 0 (list 1 2 3))
 
-> (((0 + 2*1) + (2*2)) + (2*3))
 
-> 12
 
 
 
<b>repeat-fn</b> <i>function NumTimes object</i>
 
- repeat <i>function Numtimes</i> on <i>object</i>
 
e.g. (repeat (lamda (x) (+ x 1)) 4 0)
 
-> 4
 
 
 
<b>eq-lists?</b> <i>listA listB</i>
 
- preposition: is <i>listA</i> equal to <i>listB</i> -> are all elements of A = all elements of B.
 
- Does NOT currently take into account lists of lists, so just 1D lists atm.
 
e.g. (eq-lists? `(a b c) `(d e f)) -> #f
 
(eq-lists? `(a b c) `(a b c)) -> #t
 
(eq-lists? `(a b c) `( `(a) b c)) -> Error.
 
 
 
<b>neq?</b> <i>atomA atomB</i>
 
- preposition: is <i>atomA</i> NOT equal to <i>atomB</i>
 
e.g. (neq? 1 2) -> #t
 
  
 
===KayD-StringShortcuts===
 
===KayD-StringShortcuts===

Revision as of 11:43, 14 September 2018

Public Script Modules

See the Rules Page on SWC for additional explanation.


swclib

(load "swclib")

Contact: Selatos; Kay Dallben

funlib

(load "funlib")

Contact: Selatos, Kay Dallben

KayD-StringShortcuts

This library was removed as module and cannot be loaded. However, it is possible to use the functions by copying/pasting them. These functions insert appropriate pronoun string based on gender.

(defun (female? (who self))
   (cond
      [(eq? (get-gender who) "female") #t]
      [#t #f]))
(defun (male? (who self))
   (cond
      [(eq? (get-gender who) "male") #t]
      [#t #f]))
(defun (HeShe? (who self))
   (cond
      [(female? who) "She"]
      [#t "He"]))
(defun (heshe? (who self))
   (cond
      [(female? who) "she"]
      [#t "he"]))
(defun (HerHis? (who self))
   (cond
      [(female? who) "Her"]
      [#t "His"]))
(defun (herhis? (who self))
   (cond
      [(female? who) "her"]
      [#t "his"]))
(defun (HerHim? (who self))
   (cond
      [(female? who) "Her"]
      [#t "Him"]))
(defun (herhim? (who self))
   (cond
      [(female? who) "her"]
      [#t "him"]))

Examples:

  • (say (concat "Yes, " (heshe (get-npc 54486)) " is pretty silly.")) -> "Yes, he is pretty silly."
  • (describe (concat (HerHis self) " gun points directly at you.")) -> Her gun points directly at you.
  • heshe player-NPC-object
  • HeShe player-NPC-object
  • herhis player-NPC-object
  • HerHis player-NPC-object
  • herhim player-NPC-object
  • HerHim player-NPC-object

Keyboard-Al Sayif

This Script Module (and paired NPC-Script requirements) enables a character-by-character input of a string into a script.

NPC Script Requirements

;;;; ---------------------------------------------
;; Corresponding Content for NPC/Entity
(load "Keyboard-Al Sayif" "")
(load "swclib")
(bind-keyboard-mself (get-id self) 'npc)
(bind-keyboard-convo say say-c describe describe-c ooc ooc-c)
(bind-keyboard-responses add-action add-response add-text)
(bind-keyboard-utils clear-window)
(defun oncancel
; Called when you hit the Cancel Button. Edit as needed.
(ooc "Cancelled Keyboard Input."))
(defun onfinish
; called when user clicks the Enter button. Edit as needed.
(clear-window)
(say (myconcat "Well it's very nice to meet you, Mr. " (get-keyboard-response))))
(bind-keyboard-callbacks onfinish oncancel)
(defun start ;; Example to go straight into it. Edit as needed, or just use start-keyboard.
(describe "Enter your input on the keypad. As you click the screen will update.")
(start-keyboard))
;;;; ---------------------------------------------

start-keyboard

  • clears the window and starts the Keyboard Input script: Asks for input character by character. CAPS toggles between UPPERCASE and lowercase for letter, BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`

get-keyboard-response

  • returns a string of the saved input from the keyboard.

COMING SOONTM

start-keypad

  • clears the window and starts the Keypad Input script: Asks for input character by character (numbers 0 - 9 only). BACK removes the last-entered character, CLEAR clears the input entirely, ENTER saves the input and calls `onfinish`, CANCEL saves the input and calls `oncancel`

Contact: Kay Dallben