Glimmr Form Fields

version 1/101201 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter: Numeric input fields

    Input fields can be declared to be numerical. A numerical field has an additional property, the "associated value", which will be filled with a number after the player has completed input to the field. The associated value is not updated with each keystroke--it is only calculated when the player removes focus from the field, whether by pressing return, enter, escape (or tab, though most interpreters will not recognize the tab key); the conversion to a number is handled by the "input interpretation" rules (see below). If the player has included non-numeric input in the field, then the associated value will be 0. Otherwise, the associated value will be an appropriate numeric interpretation of the player's input. For example, if the player types "0012" into the field, the associated value will be 12. Negative numbers can be entered using a minus sign, e.g. "-22" ("+22" will also serve to indicate a positive number).

    We declare a field to be numerical like so:

        My form field is a rectangle primitive. My form field is numerical.

    By default, numerical fields allow any kind of input. However, we can restrict them to allow only numbers by changing the field's accepted standard input (see above) to allow only numeric characters. The "numerical filter" is provided as a shortcut, and can be used like so:

        When play begins:
            repeat with item running through numerical g-elements:
                now the accepted standard input of item is the numerical filter.

    This will allow only the ten digits, as well as the plus and minus signs, to be typed into a numerical field.

    It may sometimes happen that we need to disallow negative numbers as well; if that is the case, there is a special phrase that will remove the minus sign (hyphen or en dash) from the numerical filter before we apply the latter to a field:

        When play begins:
            disallow negative values in numerical filter;
            repeat with item running through numerical g-elements:
                now the accepted standard input of item is the numerical filter.

    If we later need to restore the ability to enter negative values, we can repeat the process, but allowing negative values instead:

        allow negative values in numerical filter;
        now the accepted standard input of my form field is the numerical filter.