Add-ons / <<numberpool>> Macro Set

Number input macros with support for pools.

Author Thomas M. Edwards
Website http://www.motoslave.net/sugarcube/2/#downloads
Story format SugarCube 2
Last checked Sun Nov 27 2022
License BSD 2-Clause "Simplified" License
Download numberpool.zip

Index

Overview

SugarCube is a free (gratis and libre) story format for Twine/Twee.

This documentation is a reference for the <<numberpool>> macro set for SugarCube, it assumes at least a passing knowledge of SugarCube macros.

Requirements

This package requires SugarCube v2.5.0 or greater.

Files

The files included in this package are:

Installation

JavaScript

  1. Open the numberpool-macro-set.min.js file in a text editor (not a word processor) and copy its contents.
  2. Paste them into your project's script section:
    • Twine 2: Story JavaScript.
    • Twine 1/Twee: script-tagged passage.

Stylesheet

  1. Open the numberpool-macro-set.css file in a text editor (not a word processor) and copy its contents.
  2. Paste them into your project's stylesheet section:
    • Twine 2: Story Stylesheet.
    • Twine 1/Twee: stylesheet-tagged passage.

Macros

<<numberinput>>

<<numberinput>>

Syntax: <<numberinput receiverName defaultValue minValue maxValue [poolCost] [autofocus]>>

Creates a whole number input box, used to modify the value of the $variable with the given name.

Arguments:

Usage:

→ Creates a number box which modifies $Strength
<<numberinput "$Strength" $Strength 1 20>>
→ Creates an automatically focused number box which modifies $Strength
<<numberinput "$Strength" $Strength 1 20 autofocus>>

<<numberpool>>

<<numberpool>>

Syntax: <<numberpool receiverName>><</numberpool>>

Creates a number pool for use with the other macros from this set. Only useful when paired with them.

Arguments:

Usage:

<<numberpool "$StatPool">>
|''ST:''|<<numberinput "$ST" $ST 1 20>>|
|''DX:''|<<numberinput "$DX" $DX 1 20>>|
|''IQ:''|<<numberinput "$IQ" $IQ 1 20>>|
|''HT:''|<<numberinput "$HT" $HT 1 20>>|
<</numberpool>>

<<onchange>>

<<onchange>>

Syntax: <<onchange>>

Silently executes its contents when the pool is changed via one of the other macros from this set.

Arguments: none

Usage:

You have <span id="stat-pool">$StatPool</span> points remaining to allocate.
<<numberpool "$StatPool">>
|''ST:''|<<numberinput "$ST" $ST 1 20>>|
|''DX:''|<<numberinput "$DX" $DX 1 20>>|
|''IQ:''|<<numberinput "$IQ" $IQ 1 20>>|
|''HT:''|<<numberinput "$HT" $HT 1 20>>|
<<onchange>>
    <<replace "#stat-pool">>$StatPool<</replace>>
<</numberpool>>

<<numberslider>>

<<numberslider>>

Syntax: <<numberslider receiverName defaultValue minValue maxValue stepValue [autofocus]>>

Creates a number range slider, used to modify the value of the $variable with the given name.

Arguments:

Usage:

→ Creates a number slider which modifies $opacity
<<numberslider "$opacity" $opacity 0 1 0.5>>
→ Creates an automatically focused number slider which modifies $opacity
<<numberslider "$opacity" $opacity 0 1 0.5 autofocus>>

Live demo

Demo Twee code:

:: Start
<<set $points to 5>>\
<<set $str to 5>>\
<<set $int to 5>>\
<<set $dex to 5>>\
<<numberpool "$points">>
  <table>
  <tr><td>STR</td><td><<numberinput "$str" $str 1 10>></td></tr>
  <tr><td>DEX</td><td><<numberinput "$dex" $dex 1 10>></td></tr>
  <tr><td>INT</td><td><<numberinput "$int" $str 1 10>></td></tr>
  </table>\
  <<onchange>>
    <<replace "#stat-pool">>$points<</replace>>
<</numberpool>>\
You have <span id="stat-pool">$points</span> points remaining to allocate.