Howdy, Stranger!

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

Can you use multidimensional arrays in Harlowe?

I'm making a game that has a lot of different monsters that I want to choose from at random. Right now I have different categories, like hitpoints and attack values and such, as different arrays:
(set: $MonCmmnDBNumber to (a:0,1,2))
(set: $MonCmmnDBName to (a:"Lesser Kraken", "Lesser Devil Whale", "Lesser Plesiosaurus"))
(set: $MonCmmnDBHP to (a:15,15,20))
(set: $MonCmmnDBMeat to (a:15,15,20))
(set: $MonCmmnDBBones to (a:1,5,5))
(set: $MonCmmnDBShell to (a:1,0,0))
(set: $MonCmmnDBDefense to (a:1.5,1.5,1.5))
(set: $MonCmmnDBAttack to (a:4,4,5))
(set: $MonCmmnDBDex to (a:7,7,10))
(set: $MonCmmnDBKnown to (a:0,0,0))
(set: $MonCmmnDBLoc to (a:"All","America","South America")

What I would really like to do is put all of these separate variables into a single multidimensional array. Is there a way to do that? I can kind of do what I want, but I'd be able to do more if I could do multidimensional arrays...

Comments

  • There are a number of ways to create muilt-dimensional arrays, one way is to use the Array.push method:
    (set: $list to (a:))
    (set: $dummy to $list.push((a: 1,2,3,4), (a: 'a','b','c','d')))
    (set: $dummy to $list.push((a: 9,8,7,6)))
    
    list: (print: $list)
    list length: (print: $list.length)
    1st's 1st: (print: $list's 1st's 1st)
    2nd's 1st: (print: $list's 2nd's 1st)
    

    Another option is to use a combination of (array:) and (datamap:) like so:
    (set: $list to (a:))
    (set: $dummy to $list.push((datamap: "name", "john", "age", 20)))
    (set: $dummy to $list.push((datamap: "name", "jane", "age", 19)))
    list length: (print: $list.length)
    1st's name: (print: $list's 1st's name)
    2nd's name: (print: $list's 2nd's name)
    
  • Thanks. That helps a lot! Now I gotta figure out how to randomly chose monsters based on their rarity and locations. :/
  • Hi. So I have been messing around with datamaps. I'd love to be able to access entries in the datamaps with a variable, and preferably not have to access them using the 1st, 2nd, 3rd notation. But it doesn't seem to want to take a variable at all even if I just put "1st" or "1st's" as a variable like this:
    (set: $DateAndLoc to (a:))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 7, "Location", "New Bedford", "Region", "America")))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 8, "Location", "Ocean", "Region", "America")))
    
    (set: $day to "1st's")
    (print: $DateAndLoc's $day Month)
    

    Is there a way to do this that works? It's very frustrating. I feel like I'm so close to being able to do what I want to do, but it's like this one little thing...
  • edited June 2015
    GerryS wrote: »
    Is there a way to do this that works? It's very frustrating. I feel like I'm so close to being able to do what I want to do, but it's like this one little thing...
    If you look at Harlowe's overview it lists that one of the New Features in the upcoming (unreleased) 1.1.0 version is:
    Added computed property indexing syntax. Properties on collections can now be accessed via a variant of the possessive syntax: $a's (expression).

    Using this syntax, you can supply numbers as 1-indexed indices to arrays and strings. So, "Red"'s $i, where $i is 1, would be the same as "Red"'s 1st. Note, however, that if $i was the string "1st", it would also work too - but not if it was just the string "1".

    I am not sure if this new feature is in the Beta version of Harlowe being tested at the moment.

    One trick you can use while waiting for that new feature to be released is to use the (subarray:) macro to create/extact a single element array from your $DateAndLoc array, and then to reference the 1st element of that.
    (set: $DateAndLoc to (a:))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 7, "Location", "New Bedford", "Region", "America")))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 8, "Location", "Ocean", "Region", "America")))
    
    (set: $day to 1)
    (print: (subarray: $DateAndLoc, $day, $day)'s 1st's Date)
    
  • greyelf wrote: »
    I am not sure if this new feature is in the Beta version of Harlowe being tested at the moment.

    One trick you can use while waiting for that new feature to be released is to use the (subarray:) macro to create/extact a single element array from your $DateAndLoc array, and then to reference the 1st element of that.
    (set: $DateAndLoc to (a:))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 7, "Location", "New Bedford", "Region", "America")))
    (set: $dummy to $DateAndLoc.push((datamap: "Month", "June", "Date", 8, "Location", "Ocean", "Region", "America")))
    
    (set: $day to 1)
    (print: (subarray: $DateAndLoc, $day, $day)'s 1st's Date)
    

    That is definitely a solution that would work, but I would have to use it for a lot of things. Think I'll wait a little bit, and if 1.1 doesn't come out soon I'll try installing the beta and see if that works for me. Thanks!

Sign In or Register to comment.