Library of helpful STScript commands for SillyTavern.
Library of helpful STScript commands for SillyTavern.
Library of STScript commands.
/costumes command./lalib?(slash|expressions)? = slashLists LALib commands
/lalib? |
// command documentation |/lalib? expressions |
// expressions documentation |/=...[expression variables:bool|closure|dictionary|list|number|string]?...(string)Evaluates a boolean or arithmetic expression
See /lalib? expressions for more details on expressions.
/= true or false |/= 1 3 + 3 = 6) |
/reduce initial=10 [1,2,3] {: acc= cur= /= acc + cur :} |
// returns 16 (10+1 = 11 -> 11+2 = 13 -> 13 + 3 = 16) |
/let x [["a",1],["b",2],["c",3]] |
/reduce initial={} {{var::x}} {: acc= cur=
/var key=acc index={: /= cur.0 :}() {: /= cur.1 :}() |
/return {{var::acc}} |
:} |
// returns {"a":"1","b":"2","c":"3"} |/groupby(list)...(string|closure)Groups the elements of a given list according to the string values returned by a provided expression or closure.
/return [
{"x":"a", "y":1},
{"x":"b", "y":2},
{"x":"c", "y":3},
{"x":"a", "y":4},
{"x":"a", "y":5},
{"x":"b", "y":6}
] |
/groupby {{pipe}} item.x |
// returns {"a": [{...}, {...}, {...}], "b": [{...}, {...}], "c": [{...}]}
|
/return [
{"x":"a", "y":1},
{"x":"b", "y":2},
{"x":"c", "y":3},
{"x":"a", "y":4},
{"x":"a", "y":5},
{"x":"b", "y":6}
] |
/groupby {{pipe}} {: /getat index=x {{var::item}} :} |
// returns {"a": [{...}, {...}, {...}], "b": [{...}, {...}], "c": [{...}]}
|
/return [
"foo",
"foo",
"bar"
] |
/groupby {{pipe}} item |
// returns {"foo":["foo","foo"], "bar":["bar"]}
|/sorte[key:closure]?(list|varname)...(string|closure)? = (a b)Sorts a list.
The comparison closure must accept two named arguments which will be equivalent to a and b in the expression.
Using a comparison closure can be very performance and time intensive on longer lists.
If given a variable name, the variable will be modified.
See /lalib? expressions for more details on expressions.
/sorte [5,3,-10,-99,0] |
// returns [-99,-10,0,3,5] |
/let x [5,3,-10,-99,0] |
/sorte x |
/echo {{var::x}} |
// returns [-99,-10,0,3,5] |
/let x [5,3,-10,-99,0] |
/sorte {{var::x}} |
/echo {{var::x}} |
// returns [5,3,-10,-99,0] |
/sorte [5,3,-10,-99,0] (a b) |
// returns [-99,-10,0,3,5] |
/sorte [5,3,-10,-99,0] (b a) |
// returns [5,3,0,-10,-99] |
/sorte [5,3,-10,-99,0] {: a= b= /sub a b :} |
// returns [-99,-10,0,3,5] |/flatten[depth:number]? = 1(list)Creates a new list with all sub-list elements concatenated into it recursively up to the specified depth.
/flatten [1, 2, 3, [4, 5, 6, [7, 8, 9]]] |
// returns [1, 2, 3, 4, 5, 6, [7, 8, 9]] |
/flatten depth=0 [1, 2, 3, [4, 5, 6, [7, 8, 9]]] |
// returns [1, 2, 3, 4, 5, 6, 7, 8, 9] |/filter(list|dictionary)...(closure|string)Executes command for each item of a list or dictionary and returns the list or dictionary of only those items where the command returned true.
See /lalib? expressions for more details on expressions.
/filter [1,2,3,4,5] {:
/test left={{var::item}} rule=gt right=2
:} |
// returns [3, 4, 5] |
/filter [1,2,3,4,5] {: it=
/test left={{var::it}} rule=gt right=2
:} |
// returns [3, 4, 5] |
/filter [1,2,3,4,5] (item > 2) |
// returns [3, 4, 5] |/find[index=true|false]? = false[last=true|false]? = false(list|dictionary)...(closure|subcommand)Executes the provided closure or expression for each item of a list or dictionary and returns the first item where the command returned true.
See /lalib? expressions for more details on expressions.
/find [1,2,3,4,5] {:
/test left={{var::item}} rule=gt right=2
:} |
/echo |
// returns 3 |
/find [1,2,3,4,5] {: it=
/test left={{var::it}} rule=gt right=2
:} |
/echo |
// returns 3 |
/find [1,2,3,4,5] (item > 2) | /echo |
// returns 3 |/slice[start:number][end:number]?[length:number]?(string|list)?Retrieves a slice of a list or string.
/slice start=2 length=3 [1,2,3,4,5,6] | /echo |
// returns [3,4,5] |
/slice start=-8 The quick brown fox jumps over the lazy dog | /echo |
// returns lazy dog |/splice[start:number][delete:number]?[insert:list|string]?(string|number|bool|list|dictionary)?Creates a new list with some elements removed and / or replaced at a given index.
/splice insert=[30, 40, 50] start=3 delete=3 [0,1,2,3,4,5,6] |
/echo |
// returns [0,1,2,30,40,50,6] |
/splice start=3 delete=3 [0,1,2,3,4,5,6] |
/echo |
// returns [0,1,2,6] |
/splice insert=100 start=3 [0,1,2,3,4,5,6] |
/echo |
// returns [0,1,2,100,3,4,5,6] |
``No open issues yet, or sync has not completed.