Twine Version: 2.2.1
Story Format: 2.35.0
Hello! Relative newbie here, working on a turn based combat system. Whenever the player takes their turn, I’d like to be able to tell them what has happened since their last turn, like what the enemies have done. I have an array where these messages go that clears after the player sees them, but I’m having trouble saving correct values in these messages.
Here’s a simplified version of what I’m working with:
<<set $messages to >> <<set $dmg to random(7,9)>> <<set $hp -= $dmg>> <<run $messages.push('You took $dmg damage from the Python!')>> <<set $dmg to random(10,12)>> <<set $hp -= $dmg>> <<run $messages.push('You took $dmg damage from the Wolf!')>> <<= $messages.join('<br>')>>
This process is happening over the course of several looping passages. So the problem as you can probably see is that both messages will say 10-12 damage, when in fact the Python only dealt 7-9 damage.
Of course I could use different variables for each source of damage, but this gets complicated because there can be more than one of each type of enemy (so I can’t just use $wolfdmg), and each enemy can take multiple turns before the player sees the messages (so I can’t just use $enemy1dmg).
So I’m wondering if there’s a way I can “save” a variable as a string for the purposes of these messages, so that when the variable changes, the message remembers what the value was, and not what the value currently is. This sounds like what the capture macro is good for, but I can’t figure out how to use it.
EDIT: Oversimplified my example code a bit and failed to specify that the amount of damage is somewhat random. Fixed.