Help with datamaps

edited December 2015 in Help! with 2.0
So to learn Twine2 (with Harlowe) I created a small story where the player fights against 1 of 2 opponents. I setup the opponents as $enemy1 and $enemy2 and then randomly choose one of those to fight against.

To not overwrite my original definitions I use the temp variable $opponent.

While the fight only changes the values in variable $opponent it can happen that in my first action the value in $enemy1/$enemy2 changes. Any idea why? Am I doing something wrong or is there a bug in Twine2.0.10?

Comments

  • edited December 2015
    With these bits of code:
    (set: $opponent to (either: $enemy1, $enemy2))
    
    (set: $opponent to $enemy1)
    
    (set: $opponent to $enemy2)
    
    You're assigning one of the enemy maps to $opponent, not making a copy of the map (i.e. you're making $opponent a reference to the enemy map).

    To make a copy of the chosen enemy map try something like the following:
    (set: $opponent to (datamap:) + (either: $enemy1, $enemy2))
    
    (set: $opponent to (datamap:) + $enemy1)
    
    (set: $opponent to (datamap:) + $enemy2)
    
    Which creates a new empty map, then copies the contents of the original enemy map into it.
  • Excellent. Thank you very much.