Modules, New to Twine, my "New Start" - Character Stats

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?

I see the forum code removed the comments (using the Less/greater than symbols). So…

$Gap6 generates a 6-space ‘white-space’ since you can’t use spaces
$StatPT is how many points the player has to assign to stats

Very top of the “test01” passage I had the comments:
Setting character stats with a pool of points. Known issue: prevents game from accepting, but does not stop player from going (-) on $StatPT

Spacing is messed up because it processed the forced line-breaks I had inserted.

The preview should be visible in its own pane, next to the input box. Sometimes the forum software puts a huge popup in front of it (e.g. to warn you that the topic is similar to an existing topic). That happened to me when I was new to the software, and I kept looking for a preview button but couldn’t find one. Turns out I should have closed the popup. Maybe the same thing happened to you?

1 Like

First off, the code formatting symbol is hidden there in the toolbar. It looks like this: </>

And second… can’t you do something simple like this?

{
(link: “<-”) [(if: $STR is >4) [(set: $STR to it -1, $StatPT to it +1)] $RLP]
$CRed[$STR] (link: “->”) [(if: $StatPT > 1)[(set: $STR to it +1, $StatPT to it -1)] $RLP]
$Gap1 $CGreen [Strength], primarily affects damage and lifting/pushing rolls.
}

knocking myself alongside the head…can’t believe how simple that was. Probably over-thinking it.

Thank you.

1 Like

It’s funny because you already figured out the same solution for the strength, but the stats were stumping you. :grin: But that’ll happen sometimes.

Yup…sometimes it’s staring you in the face. Oh, and thank you for showing me to the </> icon.

So…trying to expand on that…always wanted a form of pop-up windows. Think I’ve come up with a possible solution suggested by Sharpe back in June 2015. I took his style-sheet idea and modified it to this:

#box
{
  position: fixed;
  right: 5%;
  top: 10%;
  width: 300px;
  height: 500px;
  overflow: auto;
  padding: 10px;
  border: solid;
  border-width: 3px;
  border-color: red;
}

Then on the next page once the player has accepted his changes, they are listed and I use this:

(click: "Strength") [<span id="box"> (display: "Strength") </span>]

to display a sort of pop-up description in the box. The problem is though…that link disappears when used. “Strength” stays, but it is no longer intractable. Originally tried it using the (link:) macro, but then the word disappears too.

Any idea how I keep the link from disappearing? Also, is it better to have a separate passage for informational pop-ups, or if it’s not too long such as:

(align: "=><=")[$CGreen[Strength]]
Primarily affects the damage one does, whether using fists or an equipped melee weapon.  It is also used say, when coming across an obstacle ... breaking down a wall, lifting a broken door, etcetera."

assign it to a variable? I would think using the variable option would use up more memory/resources??

EDIT - ANSWER:
Figured it out: eliminated the (click:) macro and went with (link-repeat:) instead…

$CYellow[$STR] (link-repeat: "Strength") [<span id="box"> (display: "Strength") </span>]

Nice thing about this is that I can eliminate a lot of code by not needing to use a (click:) entry for each word I have a pop-up for.

EDIT 2: Seems like every solution brings up a new problem. Put all the fixes and additions in. Unfortunately now when I switch from getting the pop-up on Strength and click Dexterity…it’s not erasing the previous box but writing over the top. This I am stumped on.

That you for creating your character.

Your stats are:

$CYellow[$STR] (link-repeat: "Strength") [<span id="box"> (display: "Strength") </span>]

$CYellow[$DEX] (link-repeat: "Dexterity") [<span id="box"> (display: "Dexterity") </span>]

$CYellow[$INT] (link-repeat: "Intelligence") [<span id="box"> (display: "Intelligence") </span>]

$CYellow[$WIS] (link-repeat: "Wisdom") [<span id="box"> (display: "Wisdom") </span>]

$CYellow[$VIT] (link-repeat: "Vitality") [<span id="box"> (display: "Vitality") </span>]

When ready to [[return|WhereTo]] to the test selection.

Clicking the link displays the new information…on top of what was already there. Guessing I need to put some sort of ‘clearing’ mechanism in before displaying the new…hmmm???

EDIT 3: Think I found the fix…added background-color: black; as the first entry of ‘#box’ in the style-sheet…seems to be clearing the area between uses.

EDIT 4: Another problem…If I start with say, Strength, I can continue to click on the lower items. choosing something else and I can’t select the stuff above it. Have to completely restart from the beginning and or refresh the page. Always something…no wonder can’t get anything done…