Session 11
Simple Input Forms

Field types

Compared to other scripting and programming languages, Praat is pretty lax concerning data or variable types: there's only one type for all kinds of numbers and one type for all kinds of strings. With field types, the situation is a bit more differentiated: there are 4 numeric field types and 3 string field types. The reason for this differentiation probably is, to provide you, the script author, with the means to control and restrict user input. For instance, if you ask the user to input a duration parameter you would want to restrict the input to positive numbers.

The problem is, however, that Praat's reaction to improper input is not consistent. With the field type positive, if the user puts in a negative number, an error message is presented, telling the user that the input must be greater than 0—that's fine. In case of the field type integer (i.e. if you want to restrict the input to whole numbers), no error message emerges if the user puts in a decimal number. Instead, the decimal number is silently stored as a rounded integer (e.g. 1.7 is stored as 2, 1.2 as 1). Fine, the restriction is met, but some feedback for the user wouldn't go amiss. (Remember the behavior of word: a string is simply chopped at the first space, no error message.) Therefore, if you seriously want to control user input and make your scripts react nice and consistent, you have to implement the control mechanism yourself using conditionals. Anyways, here's a list of field types for numbers and strings:

  • real  —  for real numbers (positive and negative decimal numbers)

  • positive  —  for positive real numbers

  • integer  —  for positive and negative whole numbers

  • natural  —  for unsigned (positive) integers

  • word  —  for strings without spaces

  • sentence  —  for any short strings (including spaces)

  • text  —  for any long strings (I didn't find a definition of the difference between short and long strings. Seemingly, the only difference between sentence and text is, that with sentence the variable name appears in the form as usual, while with text it doesn't.)

A special field type for a very restricted set of numbers, namely 0 (=no) and 1 (=yes), is boolean. It can be used to ask whether something should be done or not. It is displayed as a check box: checking the box means yes or true and is stored as 1, unchecking means no or false and is stored as 0.

The form below illustrates the field types. After the form is confirmed, the input is written to Praat Info.

form Input different types of data comment Enter some data and see what happens. real Real_number -273.15 positive Positive_number 373.15 integer Whole_number -76543 natural Unsigned_integer 42 boolean Want_icecream 1 word Greeting Hello sentence Phrase Hello World text Blind_text One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. endform writeInfoLine: "a real number: ", real_number appendInfoLine: "a positive number: ", positive_number appendInfoLine: "an integer: ", whole_number appendInfoLine: "a natural number: ", unsigned_integer appendInfoLine: "Icecream? ", want_icecream appendInfoLine: "a greeting: ", greeting$ appendInfoLine: "a phrase: ", phrase$ appendInfoLine: "finally, a text: ", blind_text$

The resulting form:

And the generated output (with standard values):

Next: Buttons & Menus