A set of two macros to make life easier when updating a variable and its displays.
📝 Note:
These macros are meant to be used only when the change in value needs to be shown without a passage transition. For other uses, please fall back to the <<print>> macro.
Installation
If using the Twine web/desktop app, copy the contents of live-update.js into the Edit Story JavaScript section.
If using a compiler like Tweego, just include live-update.js in your source directory.
live-update.twee-config.yaml can also be added to the workspace if using the Twee 3 Language Tools VSCode extension, for macro definitions.
Macros
<<live>>
<<l>>
<<lh>>
<<liveblock>>
<<lb>>
<<update>>
<<upd>>
Usage
<<set $testVar to 0, $testVar2 to 0>>
<<button "Add 1">>
<<set $testVar++>>
<<update>>
<</button>>
$testVar : this is potato - no updates
<<button "Add 1">>
<<set $testVar2++>>
<<update>>
<</button>>
<<live $testVar2>> : this is live
<!-- block level -->
<<button "Add 1 to both">>
<<set $testVar++, $testVar2++>>
<<update>>
<</button>>
<<liveblock>>
$testVar, $testVar2
<</liveblock>> : both are live!
Triggering the update from JavaScript
Just trigger this synthetic event:
$(document).trigger(":liveupdate");
Live demo
Demo Twee code:
:: Start
<<set $livekey to undefined>>\
<<liveblock>>\
<<if $livekey is "red">>\
You picked up the red key!
<<elseif $livekey is "blep">>\
The key disappears… You are unlucky. Go home.
<<else>>\
<<button "Pick up Key">>\
<<set $livekey to either("red", "blep")>> <!-- 50% chance of getting the key -->
<<update>>\
<</button>>\
<</if>>\
<</liveblock>>\