Howdy, Stranger!

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

Trouble moving a value from one array to another array (Harlowe 1.2.2, Twine 2.0.11)

Okay, I'm trying to move a value from one array to another, but can't seem to get it to work as this just converts array2 into a string.
(move: $destarray's 1st into $destarray2)
I'm sure there is a way to do this, but I'm just not getting it. Can anyone help?

Comments

  • AFAIK, the (move:) macro only moves values. Ergo, $destarray2 must be an array to begin with and you must select a index to move the value into. For example:
    <!-- Initialize both arrays. -->
    (set: $destarray to (a: "foo", "bar", "baz", "qaz"))
    (set: $destarray2 to (a:))
    
    <!-- Move the first value within $destarray into the first value within $destarray2. -->
    (move: $destarray's 1st into $destarray2's 1st)
    
  • edited November 2016
    Excellent, that gets me part of the way there. Now for the complicated part. That (move:) is part of a chain of possible move commands; if $thing1 is true, move $destarray's 1st; if $thing2 is true, move $destarray's 2nd; etc. This chain can occur several times as the player explores.

    Any thoughts on how to deal with the possibility of moving $destarray's 12th into $destarray2's 3rd (as a possible example)? The only thing I can think of is after the (if:) statement, get the length of $destarray2 and use that to control a list of (if:) statements:
    If length=1, move to $destarray2's 2nd
    if length=2, move to $destarray2's 3rd
    if length=x, move to $destarray2's x+1
    etc.
    
    There has to be a cleaner way... right?
  • If you simply want to append to $destarray2, then you should be able to do something like the following:
    (move: $destarray1's 1st into $destarray2's ($destarray2's length + 1))
    
    NOTE: The parenthesis around the ($destarray2's length + 1) sub-expression are required.
  • You, sir or madam, are amazing. That worked perfectly and helped solve a thing I've been banging my head against off and on for over a week.
Sign In or Register to comment.