1,007
edits
| Line 429: | Line 429: | ||
=== Lists as Noun Types === | === Lists as Noun Types === | ||
Suppose you're writing a command that takes a color as an argument (perhaps it outputs a hexadecimal RGB representation of that color.) To make a nountype that accepts colors, you can simply pass in an array of strings: | |||
<pre> | |||
names: ["convert color"], | |||
arguments: [{role: "object", | |||
nountype: ["red", "orange", "yellow", "green", | |||
"blue", "violet", "black", "white", | |||
"grey", "brown", "beige", "magenta", | |||
"cerulean", "puce"], | |||
label: "color to convert"}] | |||
</pre> | |||
One benefit of using a list is that the parser can use it offer the user suggestions. If the user enters "get-color bl", for instance, Ubiquity will be able to suggest "black" and "blue" as the two valid completions based on the input. This makes list-based nountypes very useful for any command that can accept only a finite set of values. | |||
=== Writing a Noun Type Object === | === Writing a Noun Type Object === | ||
edits