Date: 2014/08/26 21:30:47 UTC-07:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Definition_Example:
type: world
debug: false
events:
on defs command:
- determine passively fulfilled
- define args '<tern[<c.args.size.is[MORE].than[0]>]:<c.args> || li@This|is|a|default|sentence|you|silly!>'
- run locally defs instantly def:%args%
defs:
- define defs <queue.definitions>
# We can use <queue.definitions> at the beginning of a new queue to show all
# the definitions that were passed to it.
- narrate "<&sp><&3><&n>Queue Definitions"
- narrate ""
# To illustrate, the output here is the definition name %def% followed by
# the definition value <def[%def]>
- foreach %defs% {
- define def %value%
- narrate "<&sp><&sp><&sp><&6>%def%<&co> <&f><def[%def%]>"
}
# Not quite the output you would expect. That's because the
# <queue.definitions> list is built from an internal (to denizen) hashmap
- narrate ""
- narrate "*--------"
- narrate ""
# Since the list %defs% we are working with was passed from a run command,
# the definition names are the order index li@1|2|3... as seen above. This
# is helpful since the order of the list %defs% was disturbed by using the
# <queue.definitions> tag. We can sort this list by number order using the
# <list.numerical> tag.
- narrate "<&sp><&3><&n>Sorted List - Numeric"
- narrate ""
- define sortedDefs <def[defs].numerical>
# Now that we have out list of definitions back in the correct order, let's
# reconstruct the sentence you entered.
- define sentence li@
# You must create an empty list object so it's available when we try to add
# data to it. Bad things happen with non-existent lists!
# The value being added to the list is the word in your sentence, not the
# definition name!
- foreach %sortedDefs% {
- define def %value%
- narrate "<&sp><&sp><&sp><&6>%def%<&co> <&f><def[%def%]>"
- define sentence '<def[sentence].include[<def[%def%]>]>'
}
- narrate ""
# Let's display the list of definition names in sorted order.
- narrate "<&sp><&3>Definition name order reconstructed<&co> <&f><def[sortedDefs].space_separated>"
- narrate ""
# And finally your reconstructed sentence.
- narrate "<&sp><&3>Your string reconstructed<&co> <&f><def[sentence].space_separated>"
- narrate ""
- narrate "*--------"