Skip to content

AttributeHandler.js

kyleady edited this page Dec 19, 2017 · 1 revision

Purpose

This is an API Command that allows users to view and edit their attributes. However, I cannot know the attributes that you intend to use in your personal campaign. This API Command currently allows players to view/edit all of their character's attributes with no corrections for spelling, capitalization, or spacing.

Usage

!attr [max] <attribute name> <operator> [<modifier>]

  • max will signal that we are working with the maximum of the attribute instead of its current value.
  • attribute name is the name of the attribute we are working with
  • operator is the type of operation we are doing on the attribute. See NumberModifier.js.
  • modifier sign is the sign of the modifier, + or -.
  • modifier is the value of the modifier. It may also be the words current or max.

Allows players to view and edit their attributes by making use of statHandler().

Examples

!attr WS ?+ 10 would privately report the selected characters' WS attribute +10 to the user, without modifying the attributes.

!attr Int /= 2 would divide the selected characters' Int attributes by two.

!max attr S = current would set the selected characters' max S equal to the current values.

attributeHandler(matches, msg, options)

  • matches is an array of the matches delivered by CentralInput.
    • matches[0] is the same as msg.content, but is not used within this function.
    • matches[1] is whether or not the user is working with the max attribute (if == "max")
    • matches[2] is the exact name of the attribute
    • matches[3] is the text operator (as determined by numModifier)
    • matches[4] is the sign of the modifier (optional)
    • matches[5] is the absolute value of the modifier. It may also be the word max or current. (optional)
  • msg is the msg that came from the event on("chat:message", function(msg){});
  • options allows for the following
    • options["show"] - a flag for whether or not any results or alerts will be shown. By default this will be true.
    • options["partyStat"] - a flag for whether or not the attribute is a globally unique attribute shared by the whole party (ie The attribute is not held by the selected character). By default this will be false.
    • option["bar"] - the name of the token bar we are using. Limited to bar1, bar2, and bar3.

statHandler() uses eachCharacter(), applying the API Command to each selected character.

statHandler() uses attrValue(), enabling local changes on generic characters.

If the operator contains a question mark, no edits will be made. The user will be privately informed of the attribute with the modifier.

If the operator contains an equals sign, the attribute will be modified. The user and the GM will be informed of the change. If options["partyStat"] is true, the change will be a public announcement.

If you attempt to set a temporary attribute in the graphic's gmnotes equal to its max value and there is no corresponding attribute on the character sheet, the temporary attribute will be deleted. This effectively resets the temporary attribute.

Note that players will not be alerted if the gm makes a change.

correctAttributeName(name)

This function is meant be be edited by you to correct common synonyms for your Attributes into the exact Attribute name with perfect capitalization and spacing.

Currently it only trims off any extra spaces from the names.

It is used by attributeHandler().

makeAttributeHandlerRegex(attributes)

Returns a regex for attributeHandler() when adding it to the CentralInput object.

If attributes is not defined, it will create a regex that will allow any attribute name.

If attributes is an Array of strings, it will create a regex that will only allow the attribute names given. It will also not start with attr.

If attributes is a string, it will make it into an Array of that one string before continuing as usual.

Requirements

Clone this wiki locally