Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Fun With Datasets in Harlowe

I'm working with datasets and I have some questions.
First, is there a way to print the contents of a dataset for debugging purposes, or else some other way to decipher what's currently contained in one? Second, if I create a dataset of array variables, how do I add another array to the dataset in a way that means the array itself is an entry in the dataset and not that the contents of the array have been added to a dataset? Thanks!

Comments

  • edited August 2016
    Sorry I can't answer the question, but what's a dataset?
  • Deadshot wrote: »
    Sorry I can't answer the question, but what's a dataset?
    First you should read the Harlowe Manual, in particular the (dataset: ) macro and the Dataset data sections, after that you may want to read about the Javascript Set object.

    mooeena wrote: »
    ... is there a way to print the contents of a dataset for debugging purposes...
    You can use Javascript to output the set's content to your web-browser's Developer Console** but you will need to know the structure and datatypes of the values contained within it to do so because it can effect the code you need to output the values.

    If the set contains primitive datatypes like Strings or Numbers, or arrays of Strings or Numbers then you could do something like the following:
    (set: $list to (dataset: "gold", "frankincense", "myrrh"))
    
    (set: $dummy to $list.forEach(function(value1, value2, set){console.log(value1);}))
    
    (set: $list to (dataset: (a: 1,2), (a: 3,4), (a: 5,6)))
    
    (set: $dummy to $list.forEach(function(value1, value2, set){console.log(value1);}))
    
    If the set contains more complex datatypes like Arrays of Arrays, DataMaps, DataSets, or Objects then the code requires to convert each element in the set to a String output becomes more complex.

    mooeena wrote: »
    how do I add another array to the dataset...
    In a similar way to how you dynamically add extra items to an (array:), with arithmetic.
    (set: $list to (dataset:))
    (set: $list to it + (dataset: (a: 1,2)))
    (set: $list to it + (dataset: (a: 3,4)))
    (set: $list to it + (dataset: (a: 5,6)))
    
    (set: $dummy to $list.forEach(function(value1, value2, set){console.log(value1);}))
    
Sign In or Register to comment.