Howdy, Stranger!

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

Adding Datamaps

So I have a Datamap that contains the character's statistics and the values of each statistic.
This datamap I call $Attributes.
I can access elements of this because I know what they are. $Attributes's Ferocity, for instance. At first this seemed like a convienent data management method, but now I'm running into an issue.

What I want to do is add $Attributes to another Datamap (for instance, you have reached a new level up, or something), and have the result be adding the Values of each datamap together. The thing that caught me off guard is that Harlowe's implementation for addition of datamaps just uses the values from the rightmost Datamap when they are added (if the name is in both Datamaps).

Is there a way to get this working with Datamaps, or should I rewrite all my code to use arrays?

Comments

  • The approach I'm looking at right now is a nested loop that iterates through the datamaps and adds the values if they contain the same element. I think this will work once I iron it out but it's a little disappointing that the default addition doesn't handle it.
  • edited April 2016
    This is what I came up with

    Method to Add Datamaps 1 and 2

    datamap Datamap1
    datamap Datamap2
    datamap Output
    array Names1 = (datanames (Datamap1)
    array Names2 = (datanames (Datamap2)
    array Values1 = (datavalues (Datamap1)
    array Values2 = (datavalues (Datamap2)

    x = 0
    y = 0

    while (x < length of Names2)
    {
    if (Names1 contains Names2[x])
    {
    y = 0
    while (y < length of Names1)
    {
    if( Names1[y] == Names2[x])
    {
    add Names1[y] to Output, add Values1[y] + Values2[x] to Output
    }
    y++
    }
    }
    else
    {
    add Names2[x] to Output, add Values2[x] to Output
    }
    x++
    }
    x = 0
    while (x < length of Names1)
    {
    if (Names2 does not contain Names1[x])
    {
    add Names1[x] to Output, add Values1[x] to Output
    }
    x++
    }
Sign In or Register to comment.