Howdy, Stranger!

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

Array to Datamap?

edited September 2015 in Help! with 2.0
It seems like this should work but doesn't quite seem to..? Trying to work with datamaps
1. (set: $commandParams to (a: "aparam0", "avalue0", "aparam1", "avalue1"))
2. (print: $commandParams's 1st)=aparam0 (print: $commandParams's 2nd)=aparam1
3. (print: (datamap: "dparam0", "dvalue0", "dparam1", "dvalue1")'s "dparam0")=dvalue0
4. (print: (datamap: $commandParams)'s "aparam0")=gives an error
5s. (set: $datamap0 to (datamap: "dparam0", "dvalue0", "dparam1", "dvalue1"))
5p. correct: {(print: $datamap0)}
6s. (set: $datamap1 to (datamap: $commandParams))
6p. error:0 = {(print: $datamap1)}

Specifically the errors come out as "This datamap has a data name without a value"

I know I could just manually put in everything word by word, but I'm trying to use datamap dynamically so may not know the array length - any way of converting from an array of strings into a datamap, if you don't know the exact size of the array?

Comments

  • The (datamap:) macro requires an even number of parameters, but you're only providing one, the array. In order to pass the elements of the array to the macro you need to use the ... operator.

    This should do what you want
    (set: $datamap1 to (datamap: ...$commandParams))
    
  • Perfect, that absolutely work, thank you!!!! You totally rock!
Sign In or Register to comment.