To handle random values elegantly, you can define a <randomGenerator> element at the root:

<chapter id="soldier"> <scene id="battle"> <description>War comes. Do you charge or wait?</description> <choiceList> <choice action="victoryEnding"> <text>Charge heroically. (Requires strength > 8)</text> <effect> <modify var="reputation" by="+50"/> <addInventory>Sword of Valor</addInventory> </effect> </choice> <choice action="deathEnding"> <text>Retreat and live as a deserter.</text> <effect> <modify var="reputation" by="-100"/> <gameOver reason="Cowardice" /> </effect> </choice> </choiceList> </scene> </chapter>

// Apply effect based on user input (pseudo) function applyEffect(effects) { effects.modify.forEach(mod => { playerStats[mod.$.stat] += parseInt(mod.$.value); }); } });