Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.5
Story Format: Harlow 3.1
Introduced to Twine a couple months ago, thought I had a few good ideas bit U kept getting seriously side-tracked from having to figure things out. Nothing saps a good roll like getting interrupted for several hours trying to figure something out.
So I’ve decided to start over by creating what I’m calling ‘Modules’, things I figure I’ll need in upcoming projects. Knowing there are tons of people here who have been doing this for years, I’m hoping 1) this will be a good place to post these things; 2) that others will follow suit; 3) and the experienced people will help me improve my coding.
This first one is my Character Stat Generator where the player can adjust his starting stats. Short of inserting a lot of extra code, the issue I’m having is preventing the player from generating a negative (-) number of available points in the first place. I’m only listing 2 of the 5 stats ( there is also INT, WIS, and VIT).
In the startup passage (I am not including the variable for the stats to save space):
(set: $Gap6 to “\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0”)
(set: $Note to (css: “font-size 12px”)+(color: orange))
(set: $CYellow to (color: yellow))
(set: $CRed to (color: red))
(set: $Title to (css: “font-size: 24px”)+(color: green)+(text-style: “underline”))
(set: $StatPT to 10)
In the TEST01 passage, the $RLP value is set on the introduction page depending on what module I am working on. It stands for ‘Reload Passage’ and is used when a page needs reloading as used in the following example. From my 'WhereTo’aka ‘Start Story Here’ passage:
Welcome to the Sandbox Test - What do you want to work on today?
(link: “Test 01”) [(set: $RLP to (goto: “TEST01”)) $RLP]: Character Statistics
From the ‘TEST01’ Passage
{
$Title [Character Statistics]
}
{
(if: $StatPT is 0) [$Gap10 You have no more points to allocate.]
(else:)[$Gap10 $CYellow[Assign remaining Points]: $CRed [$StatPT] $Note [$Gap10 Note: Statistics may not be reduced below 4] ]
}
{
(link: “<-”) [(if: $STR is >4) [(set: $STR to it -1, $StatPT to it +1)] $RLP]
$CRed[$STR] (link: “->”) [(set: $STR to it +1, $StatPT to it -1) $RLP]
$Gap1 $CGreen [Strength], primarily affects damage and lifting/pushing rolls.
}
{
(link: “<-”) [(if: $DEX is >4) [(set: $DEX to it -1, $StatPT to it +1)] $RLP]
$CRed[$DEX] (link: “->”) [(set: $DEX to it +1, $StatPT to it -1) $RLP]
$Gap1 $CGreen [Dexterity], primarily affects Ranged Damage, dodging, , speed and stealth.
}
.
…the other three stats were here, all starting at 7
.
{
Accept these statistics?
(if: $StatPT is >0) [$CYellow [You have points remaining, accept anyways? [[Yes|TEST01A]] ]]
(if: $StatPT is 0) [ [[Yes|TEST01A]] ]
(if: $StatPT is <0) [ $CRed [You have used more points than allowed, correct to continue.]]
}
It works nicely except for the ability to have negative points. Only way I can see to eliminate that is by adding extra nesting (if:) statements. Either that or an (if:) that encompasses the current stat adjustment above, and when the count gets to 0 it shifts to asking if the player accepts. Issue with that is…prevents the player from further adjustment once he reaches 0.
Wanted to use courier for the code part, but couldn’t figure out how to set font here. So sorry if the code is messed up from copy-paste. And no preview before posting option?