Skip to content

Commit 16d4184

Browse files
committed
More tweaks to the scripting guide
1 parent aeaec0f commit 16d4184

File tree

2 files changed

+79
-178
lines changed

2 files changed

+79
-178
lines changed

Library/Markdown/Help/Interface/Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Any panel with a question mark icon ( ![](./img/q.png "Help") ) will open Help r
6666
21. [Container](./Container.md)
6767
22. [Toggle State](./Toggle%20State.md)
6868
7. [Markdown Guide](../Markdown%20Guide.md)
69-
8. [Scripting](../Scripting.md)
69+
8. [Scripting Guide](../Scripting%20Guide.md)
7070
9. [Expression Function Reference](../Expression%20Functions.md)
7171
10. [Expression Operators Reference](../Expression%20Operators.md)
7272

Lines changed: 78 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
# Scripting
1+
# Scripting Guide
22

33
> Available in GCS 5.36.0 and later.
44
55
Some fields, such as notes, support using Javascript to resolve their content. Versions of GCS prior to v5.36.0 used a
66
simple expression evaluator instead. Expressions from those old data files will be automatically transformed into the
77
equivalent Javascript.
88

9-
For fields that aren't exclusively a script, such as note fields, you must embed your scripts by wrapping them in script
10-
tags, like this:
9+
Fields that are intended to resolve to a number and either contain a number or a script. Fields that are intended to
10+
resolve to text, however, must have the scripting portion(s) wrapped in tags, like this:
1111

1212
```
13-
My ST + DX is <script>$st + $dx</script>!
13+
My ST + DX is <script>$st + $dx</script> and my name is <script>entity.name</script>.
1414
```
1515

1616
When your Javascript code is called, the following globals will be available for you to use:
1717

1818
- `console`
1919
- `dice`
2020
- `entity`
21-
- `fixed`
2221
- `iff`
23-
- `length`
2422
- `Math.exp2`
23+
- `measure`
2524
- `self`
2625
- `signedValue`
27-
- `ssrt`
28-
- `weight`
2926

3027
In addition, any attributes you've defined for the sheet are available as globals using their ID prefixed with a dollar
3128
sign, e.g. `$st` refers to the Strength attribute.
@@ -114,6 +111,29 @@ This object holds encumbrance-related data for an entity.
114111

115112
This object represents the current character sheet data.
116113

114+
### Properties for entity
115+
116+
- `exists: boolean`: true if this script is being run on a sheet.
117+
- `playerName: string`: The player's name.
118+
- `name: string`: The entity's name.
119+
- `title: string`: The entity's title.
120+
- `organization: string`: The entity's organization.
121+
- `religion: string`: The entity's religion.
122+
- `techLevel: string`: The entity's tech level.
123+
- `gender: string`: The entity's gender.
124+
- `age: string`: The entity's age.
125+
- `birthday: string`: The entity's birthday.
126+
- `eyes: string`: The entity's eyes.
127+
- `hair: string`: The entity's hair.
128+
- `skin: string`: The entity's skin.
129+
- `handedness: string`: The entity's handedness.
130+
- `displayHeightUnits: string`: The height units that should be used for display.
131+
- `displayWeightUnits: string`: The weight units that should be used for display.
132+
- `heightInInches: number`: The entity's height, in inches.
133+
- `weightInPounds: number`: The entity's weight, in pounds,
134+
- `sizeModifier: number`: The entity's size modifier.
135+
- `extraDiceFromModifiers: boolean`: true if the Modifying Dice + Adds option from B269 is in use.
136+
117137
### Methods for entity
118138

119139
- `attribute(idOrName: string): attribute`: Returns the attribute that matches the given ID or name. IDs are checked
@@ -124,8 +144,6 @@ This object represents the current character sheet data.
124144
modifier is adjusted to account for equipment that has been marked as not having its weight counting against skills.
125145
- `encumbrance(): encumbrance`: Returns the encumbrance data.
126146
- `equipment(): Array<equipment>`: Returns the top-level carried equipment with a quantity greater than 0.
127-
- `exists(): boolean`: Returns true if this script is being run on a sheet.
128-
- `extraDiceFromModifiers(): boolean`: Returns true if the Modifying Dice + Adds option from B269 is in use.
129147
- `findEquipment(name: string, tag: string): Array<equipment>`: Returns the carried equipment that match the given
130148
'name' and has the given 'tag', case-insensitively. When matching, an empty or undefined value passed in will match
131149
everything. Note that only equipment with a quantity greater than 0 is considered and if all parents of that equipment
@@ -139,13 +157,12 @@ This object represents the current character sheet data.
139157
- `findTraits(name: string, tag: string): Array<trait>`: Returns the enabled traits that match the given 'name' and have
140158
the given 'tag', case-insensitively. When matching, an empty or undefined value passed in will match everything.
141159
- `hasTrait(name: string): boolean`: Returns true if the named trait is present and enabled.
142-
- `randomHeight(strength: number): number`: Returns a height in inches based on the given 'strength' using the chart
143-
from B18.
144-
- `randomWeight(strength: number, shift: number): number`: Returns a weight in pounds based on the given 'strength'
145-
using the chart from B18. Adjusts appropriately for the traits Skinny, Overweight, Fat, and Very Fat, if present on
146-
the sheet. 'shift' causes a shift towards a lighter value if negative and a heavier value if positive, similar to
147-
having one of the traits Skinny, Overweight, Fat, and Very Fat applied, but is additive to them.
148-
- `sizeModifier(): number`: Returns the size modifier of the entity.
160+
- `randomHeightInInches(strength: number): number`: Returns a height in inches based on the given 'strength' using the
161+
chart from B18.
162+
- `randomWeightInPounds(strength: number, shift: number): number`: Returns a weight in pounds based on the given
163+
'strength' using the chart from B18. Adjusts appropriately for the traits Skinny, Overweight, Fat, and Very Fat, if
164+
present on the sheet. 'shift' causes a shift towards a lighter value if negative and a heavier value if positive,
165+
similar to having one of the traits Skinny, Overweight, Fat, and Very Fat applied, but is additive to them.
149166
- `skills(): Array<skill>`: Returns the top-level enabled skills.
150167
- `skillLevel(name: string, specialization: string, relative: boolean): number`: Returns the level of the skill with the
151168
given 'name' and 'specialization'. If 'relative' is true, returns the relative level instead.
@@ -155,7 +172,6 @@ This object represents the current character sheet data.
155172
- `traits(): Array<trait>`: Returns the top-level enabled traits.
156173
- `weaponDamage(name: string, usage: string): string`: Returns the weapon damage for the weapon entry that matches the
157174
given 'name' and 'usage', or an empty string if none is found.
158-
- `weightUnits(): weightUnit`: Returns the default weight units to use for the entity.
159175

160176
## equipment
161177

@@ -187,122 +203,62 @@ This object holds data for equipment.
187203
- `value(): number`: The value of one of these items.
188204
- `weight(): number`: The weight in pounds of one of these items.
189205

190-
## fixed
191-
192-
This object provides a fixed-point numeric data type, which is used for all potentially non-integer calculations within GCS so that various floating-point errors don't occur. It is provided here so that you can do fixed-point calculations where needed.
193-
194-
### Static Properties for fixed
195-
196-
- `maxSafeMultiply: fixed`: The maximum value that can be safely multiplied without overflow.
197-
- `maxValue: fixed`: The maximum value that a fixed value can hold.
198-
- `minValue: fixed`: The minimum value that a fixed value can hold.
199-
- `zero: fixed`: Convenience for the constant 0.
200-
- `tenth: fixed`: Convenience for the constant 0.1.
201-
- `eighth: fixed`: Convenience for the constant 0.125.
202-
- `quarter: fixed`: Convenience for the constant 0.25.
203-
- `half: fixed`: Convenience for the constant 0.5.
204-
- `one: fixed`: Convenience for the constant 1.
205-
- `two: fixed`: Convenience for the constant 2.
206-
- `three: fixed`: Convenience for the constant 3.
207-
- `four: fixed`: Convenience for the constant 4.
208-
- `five: fixed`: Convenience for the constant 5.
209-
- `ten: fixed`: Convenience for the constant 10.
210-
- `hundred: fixed`: Convenience for the constant 100.
211-
- `thousand: fixed`: Convenience for the constant 1000.
212-
213-
### Static Methods for fixed
214-
215-
- `asInteger(value: fixed): number`: Returns the value converted to an integer.
216-
- `asFloat(value: fixed): number`: Returns the value converted to a float.
217-
- `fromString(str: string): fixed`: Parses the string and returns the fixed value from it.
218-
- `fromInteger(value: number): fixed`: Returns the integer value converted to a fixed-point value.
219-
- `fromFloat(value: number): fixed`: Returns the floating-point value converted to a fixed-point value.
220-
- `applyRounding(value: fixed, roundDown: boolean): fixed`: Rounds a value in the positive direction if 'roundDown' is
221-
false, or in the negative direction if 'roundDown' is true, returning the result.
222-
223-
### Methods for fixed
224-
225-
- `add(value: fixed): fixed`: Returns the result of adding the supplied value to this value.
226-
- `sub(value: fixed): fixed`: Returns the result of subtracting the supplied value from this value.
227-
- `mul(value: fixed): fixed`: Returns the result of multiplying the supplied value with this value.
228-
- `div(value: fixed): fixed`: Returns the result of dividing this value by the supplied value.
229-
- `mod(value: fixed): fixed`: Returns the remainder after subtracting all full multiples of the provided value from this
230-
value.
231-
- `abs(): fixed`: Returns the absolute value of this value.
232-
- `trunc(): fixed`: Returns this value with everything to the right of the decimal place truncated.
233-
- `ceil(): fixed`: Returns the value rounded up to the nearest whole number.
234-
- `round(): fixed`: Returns the nearest integer, rounding half away from zero.
235-
- `min(value: fixed) fixed`: Returns the minimum of the provided value or this value.
236-
- `max(value: fixed) fixed`: Returns the maximum of the provided value or this value.
237-
- `inc(): fixed`: Returns this value incremented by 1.
238-
- `dec(): fixed`: Returns this value decremented by 1.
239-
- `string(): string`: Returns the text representation of this value.
240-
- `stringWithSign(): string`: Returns the same value as '.string()', but with a leading '+' if the value is positive.
241-
- `comma(): string`: Returns a text representation of this value with commas separating every third digit before the
242-
decimal place.
243-
- `commaWithSign(): string`: Returns the same value as '.comma()', but with a leading '+' if the value is positive.
244-
245206
## iff
246207

247208
This is a top-level function.
248209

249210
- `iff(condition: boolean, trueValue: any, falseFalue: any): any`: Returns 'trueValue' if 'condition' is true, otherwise
250211
returns 'falseFalue'.
251212

252-
## length
253-
254-
This object provides handling of lengths.
255-
256-
### Static Properties for length
257-
258-
- `feetAndInches: lengthUnit`: The feet and inches unit, which dynamically adjusts to one of three displays, depending
259-
on the value:
260-
1. Showing feet and inches, e.g. 5'9"
261-
2. Showing feet, e.g. 5'
262-
3. Showing inches, e.g. 3"
263-
- `inch: lengthUnit`: The inches unit, represented as 'in'.
264-
- `feet: lengthUnit`: The feet unit, represented as 'ft'.
265-
- `yard: lengthUnit`: The yards unit, represented as 'yd'.
266-
- `mile: lengthUnit`: The miles unit, represented as 'mi'.
267-
- `centimeter: lengthUnit`: The centimeters unit, represented as 'cm'.
268-
- `meter: lengthUnit`: The meters unit, represented as 'm'.
269-
- `kilometer: lengthUnit`: The kilometers unit, represented as 'km'.
270-
271-
### Static Methods for length
272-
273-
- `unitsFromString(str: string): lengthUnit`: Returns the length unit whose key matches 'str', or length.feetAndInches
274-
if there is no match.
275-
- `fromString(value: string, defaultUnits: lengthUnit): length`: Returns a new length object by parsing the input
276-
string. If no units are present in the string, then 'defaultUnits' is used. If 'defaultUnits' isn't provided, uses
277-
length.feetAndInches.
278-
- `fromInteger(value: number, units: lengthUnit): length`: Returns a new length object. If no 'units' are provided, uses
279-
length.feetAndInches.
280-
- `fromFixed(value: fixed, units: lengthUnit): length`: Returns a new length object. If no 'units' are provided, uses
281-
length.feetAndInches.
282-
- `fromFloat(value: number, units: lengthUnit): length`: Returns a new length object. If no 'units' are provided, uses
283-
length.feetAndInches.
284-
- `asFixedInches(value: length): fixed`: Returns the 'length' as a fixed value of inches.
285-
286-
### Methods for length
287-
288-
- `string(): string`: Returns the length formatted in feet and inches.
289-
290-
## lengthUnit
291-
292-
This object provides conversion of length values to specific units.
293-
294-
### Methods for lengthUnit
295-
296-
- `key(): string`: Returns the key representing this length unit.
297-
- `format(value: length): string`: Returns a string representation of the 'value' in these units, e.g. '12 yd'.
298-
- `toInches(value: fixed): fixed`: Returns the 'value' in these units converted to inches.
299-
300213
## Math.exp2
301214

302215
This is actually just an addition to the standard Javascript Math object.
303216

304217
- `Math.exp2(value: number): number`: Returns 2 raised to the power of the `value`.
305218

219+
## measure
220+
221+
This object provides measurement utilities.
222+
223+
Valid units for lengths are:
224+
225+
- in
226+
- ft
227+
- ft_in
228+
- yd
229+
- mi
230+
- cm
231+
- m
232+
- km
233+
234+
Valid units for weights are:
235+
236+
- oz
237+
- lb
238+
- \#
239+
- tn
240+
- t
241+
- g
242+
- kg
243+
244+
### Static Methods for measure
245+
246+
- `formatLength(inches: number, toUnits: string): string`: Formats a length (in inches) into a string with the given
247+
units.
248+
- `lengthToInches(value: number, fromUnits: string): number`: Converts a length value of the given units into inches.
249+
- `stringLengthToInches(str: string, defaultUnits: string): number`: Converts a string containing a length into inches.
250+
If no units are found in the string, then 'defaultUnits' will be used to interpret the value.
251+
- `formatWeight(pounds: number, toUnits: string): string`: Formats a weight (in pounds) into a string with the given
252+
units.
253+
- `weightToPounds(value: number, fromUnits: string): number`: Converts a weight value of the given units into pounds.
254+
- `stringWeightToPounds(str: string, defaultUnits: string): number`: Converts a string containing a weight into pounds.
255+
If no units are found in the string, then 'defaultUnits' will be used to interpret the value.
256+
- `rangeModifier(yards: number): number`: Converts the given yards into a range modifier.
257+
- `sizeModifier(yards: number): number`: Converts the given yards into a size modifier.
258+
- `modifier(length: number, units: string, forSize: boolean): number`: Converts the given length into either a range
259+
modifier (if 'forSize' is false) or a size modifier (if 'forSize' is true).
260+
- `modifierToYards(modifier: number): number`: Converts a range or size modifier into yards.
261+
306262
## self
307263

308264
This will be set to the object that the script is attached to. Note that in some cases, this will be `undefined`, such
@@ -380,18 +336,6 @@ This object holds data for a spell.
380336
- `level(): number`: The computed level.
381337
- `relativeLevel(): number`: The computed level relative to the controlling attribute.
382338

383-
## ssrt
384-
385-
This object provides calculations on the Size and Speed/Range Table from Basic, page 550.
386-
387-
### Static Methods for ssrt
388-
389-
- `modifier(length: number, units: string, forSize: bool): number`: Calculates the number of yards from the given
390-
'length' and 'units', then returns the size modifier if 'forSize' is true or the range modifier if it is false.
391-
- `modifierToYards(ssrtValue: number): number`: Returns the yards for the given 'ssrtValue'.
392-
- `rangeModifier(yards: number): number`: Returns the range modifier for the given number of 'yards'.
393-
- `sizeModifier(yards: number): number`: Returns the size modifier for the given number of 'yards'.
394-
395339
## trait
396340

397341
This object holds data for a trait.
@@ -402,7 +346,7 @@ This object holds data for a trait.
402346
- `parentID: string`: The parent's object ID.
403347
- `name: string`: The name.
404348
- `kind: string`: The kind of container, one of 'group', 'alternative abilities', 'ancestry', 'attributes', or 'meta trait'.
405-
- `levels: fixed`: The levels, if any.
349+
- `levels: number`: The levels, if any.
406350
- `tags: Array<string>`: The associated tags.
407351
- `container: boolean`: If true, this trait is a container.
408352
- `hasChildren: boolean`: If true, this trait has children.
@@ -414,49 +358,6 @@ This object holds data for a trait.
414358
given 'name' and have the given 'tag', case-insensitively. When matching, an empty or undefined value passed in will
415359
match everything.
416360

417-
## weight
418-
419-
This object provides handling of weights.
420-
421-
### Static Properties for weight
422-
423-
- `pound: weightUnit`: The pounds unit, represented as 'lb'.
424-
- `poundAlt: weightUnit`: An alternate pounds unit, represented as '#'.
425-
- `ounce: weightUnit`: The ounces unit, represented as 'oz'.
426-
- `ton: weightUnit`: The tons unit, represented as 'tn'.
427-
- `tonAlt: weightUnit`: An alternate tons unit, represented as 't'.
428-
- `kilogram: weightUnit`: The kilograms unit, represented as 'kg'.
429-
- `gram: weightUnit`: The grams unit, represented as 'g'.
430-
431-
### Static Methods for weight
432-
433-
- `unitsFromString(str: string): weightUnit`: Returns the weight unit whose key matches 'str', or weight.pound if there
434-
is no match.
435-
- `fromString(value: string, defaultUnits: weightUnit): weight`: Returns a new weight object by parsing the input
436-
'value'. If no units are present in the string, then 'defaultUnits' is used. If 'defaultUnits' isn't provided, uses
437-
weight.pound.
438-
- `fromInteger(value: number, units: weightUnit): weight`: Returns a new 'weight' object. If no 'units' are provided,
439-
uses weight.pound.
440-
- `fromFixed(value: fixed, units: weightUnit): weight`: Returns a new 'weight' object. If no 'units' are provided, uses
441-
weight.pound.
442-
- `fromFloat(value: number, units: weightUnit): weight`: Returns a new 'weight' object. If no 'units' are provided, uses
443-
weight.pound.
444-
- `asFixedPounds(value: weight): fixed`: Returns the 'value' as a fixed-point number of pounds.
445-
446-
### Methods for weight
447-
448-
- `string(): string`: Returns the weight formatted as pounds.
449-
450-
## weightUnit
451-
452-
This object provides conversion of weight values to specific units.
453-
454-
### Methods for weightUnit
455-
456-
- `key(): string`: Returns the key representing this weight unit.
457-
- `format(value: weight): string`: Returns a string representation of the 'value' in the given units, e.g. '12 kg'.
458-
- `toPounds(value: fixed): fixed`: Returns the 'value' of this unit converted to pounds.
459-
460361
---
461362

462363
***Last updated for v5.36.0***

0 commit comments

Comments
 (0)