Data Manipulation Example


Author: |Anthony|
Created: 2014-08-27T14:00:40-0400
Edited: 2014-08-27T14:00:40-0400
Denizen Version: 0.9.5-b1517
Views: 19
Downloads: 750
Likes: 2


WGET
Description: :) If you have time to use my scripts, you have time to leave a comment or thumbs up!

A little example of definitions, ternary tags, sorting, and list manipulation.

Type the /defs command and see the magic!
Add any string you want just for fun
/defs herpa derpa doo motha fluffa!



I want comments! Rip it apart! What have i done absolutely wrong? What have i done absolutely right?
Has this script helped you in any way? Did you try to use it and it just didn't work?

Thumbs Up are nice too!


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 "*--------"




Comments
No one has posted a comment! Post one below: