0 votes
by (230 points)
edited by

Hi, I have several characters in my story which have their own datamaps. Something like this:

(set: $characterA to (dm:
"Money",1000
))
(set: $characterB to (dm:
"Money",2000
))

Now, depending on the character I am controlling, I assign a variable called $player to the respective datamap. And if I write the following code, it works properly and prints 1000 (characterA's Money)

(set: $player to $characterA)
(print: $player's Money)

However, if I change the Money value of $player, it does not update $characterA's Money. For example, the following still gives 1000, instead of 5000:

(set: $player's Money to it + 4000)
(print: $characterA's Money)

Am I trying to do something impossible?

 

3 Answers

+1 vote
by (360 points)

Hey ( ^ _ ^ )/

I am fairly new to twine myself, but from what I underestood based on what you said: 

(set: $player to $characterA)

That ^ doesn't connect the two together, it just copies the values that were in CharacterA and pasts it in player,

which is why when you add value to player, it doesn't add on CharacterA, they are two seperate enteties (if that makes sense) but then again... I am new to this and I could be wrong

by (230 points)
Thanks for the quick reply. Yes, I believe your explanation is the right answer. But I wonder if there is a smarter way to do this.
by (63.1k points)
reshown by
Unfortunately Harlowe clones everything. I don't think there's any way around that.
0 votes
by (230 points)

Ok, I decided to follow a slightly different approach. All the characters are defined in an array of datamaps. I change the active character by another number variable of $player. For now, this works:

(set: $chars to (a:
(dm:
"Money",1000
),
(dm:
"Money",2000
)
)
)

(set: $player to 1)
(print: $chars's $player's Money)
(set: $chars's $player's Money to it + 4000)
(print: $chars's $player's Money)

 

0 votes
by (6.2k points)
The reason it doesn't work is because setting $player to $characterA doesn't link the two, it just copes what $characterA is storing to $player. You need to set $player to $characterA again if you update $characterA. Perhaps you could consider putting the code for that in the header so it is updated every time the player moves to another passage.
...