# "Player Statistics": SugarCube (v2.18)#

## Summary#

One of the most popular mechanics of table-top role-playing games are those where the player must determine their in-game statistics and then use them to make decisions.

In this example, the `<<link>>` macro is used multiple times to replace content and adjust values based on `<<if>>` they are greater than a target number. In a second passage, these values are used in combination with a random number between 1 to 6, mimicking a common 1d6 mechanic to check if a value is above a target number.

## Twee Code#

``````:: StoryTitle
Player Statistics in SugarCube

:: Start
Empathy: \
<<if \$totalPoints gt 0>>
<<set \$empathy++>>
<<set \$totalPoints-->>
<<replace "#empathyStat">><<print \$empathy>><</replace>>
<<replace "#pointsStat">><<print \$totalPoints>><</replace>>
<</if>>
<<if \$empathy gt 0>>
<<set \$empathy-->>
<<set \$totalPoints++>>
<<replace "#empathyStat">><<print \$empathy>><</replace>>
<<replace "#pointsStat">><<print \$totalPoints>><</replace>>
<</if>>
Intelligence: \
<<if \$totalPoints gt 0>>
<<set \$intelligence++>>
<<set \$totalPoints-->>
<<replace "#intelligenceStat">><<print \$intelligence>><</replace>>
<<replace "#pointsStat">><<print \$totalPoints>><</replace>>
<</if>>
<<if \$intelligence gt 0>>
<<set \$intelligence-->>
<<set \$totalPoints++>>
<<replace "#intelligenceStat">><<print \$intelligence>><</replace>>
<<replace "#pointsStat">><<print \$totalPoints>><</replace>>
<</if>>
<<set \$empathy to 10>>
<<set \$intelligence to 10>>
<<set \$totalPoints to 5>>
<<replace "#empathyStat">><<print \$empathy>><</replace>>
<<replace "#intelligenceStat">><<print \$intelligence>><</replace>>
<<replace "#pointsStat">><<print \$totalPoints>><</replace>>

Empathy: <span id="empathyStat">10</span>
Intelligence: <span id="intelligenceStat">10</span>
Remaining Points: <span id="pointsStat">5</span>

[[Test Stats]]

:: StoryInit
<<set \$empathy to 10>>
<<set \$intelligence to 10>>
<<set \$totalPoints to 5>>

:: Test Stats
<<set _result to random(1, 6) + \$intelligence >>
<<if _result gte 15>>
Intelligence Success! (_result >= 15)
<<else>>
Intelligence Failure! (_result < 15)
<</if>>