Stat Distribution System Using Numerical Variables [HELP]

twine 2.7.1 / sugarcube2.36.1

hi all! i’m in the process of revising one of my games and I’d like to include a character creator with a stat distribution system, similar to something like the [S.P.E.C.I.A.L.] points distribution system from fallout 4.

that being said, I’m in the process of creating a stat system that allows you to distribute ‘points’ to each character trait from a pool of existing points. now, I figured out how to get as far as the altering the numbers with something that looks like this – it changes the total value of points allotted to the strength stat, while also pulling from the total pool of points.

so far, my code looks something like this:

`:: cc`

`<<link "<-">>
<<set $strengthvalue -= 1>>
     <<set $totalpts += 1>>
         <<update>>
               <</link>>`

`<<liveblock>>$strengthvalue<</liveblock>

<<liveblock>>
     <<if $strengthvalue lte $totalpts and $totalpts gte 0>>
              <<link "->">>
                    <<set $strengthvalue += 1>><<set $totalpts -= 1>>
                           <<update>>
                                    <</link>>
<<elseif $strengthvalue gte $totalpoints>>
          display null
            <</if>>
              <</liveblock>>`

`<<link "<-">>
<<set $luckvalue -= 1>>
     <<set $totalpts += 1>>
         <<update>>
               <</link>>`

`<<liveblock>>$luckvalue<</liveblock>

<<liveblock>>
     <<if $luckvalue lte $totalpts and $totalpts gte 0>>
              <<link "->">>
                    <<set $luckvalue += 1>><<set $totalpts -= 1>>
                           <<update>>
                                    <</link>>
<<elseif $luckvalue gte $totalpoints>>
          display null
            <</if>>
              <</liveblock>>`


`<<link "<-">>
<<set $intvalue -= 1>>
     <<set $totalpts += 1>>
         <<update>>
               <</link>>`

`<<liveblock>>$intvalue<</liveblock>

<<liveblock>>
     <<if $intvalue lte $totalpts and $totalpts gte 0>>
              <<link "->">>
                    <<set $intvalue += 1>><<set $totalpts -= 1>>
                           <<update>>
                                    <</link>>
<<elseif $intvalue gte $totalpoints>>
          display null
            <</if>>
              <</liveblock>>`



`<<liveblock>>$totalpts<</liveblock>>`

`:: StoryInit`

`<<set $strengthvalue to 1>>`

`<<set $totalpts to 15>>`

`<<set $luckvalue to 1>>`

`<<set $intvalue to 1>>`

This works alright, but as you might imagine–it never lets me get the pool from which I’m taking the points down to 0.

Now, I’m certain that there are better ways to achieve what I’ve described here and while I’ve been coding in twine for a little over a year now–I’d say I’m still fairly new to the language, so if anyone has any suggestions or ideas of what I could do to either fix this/a different way to achieve what I’ve described, I would be super grateful!

thank you! :slight_smile:

[[ETA: code was a little jumbled in original post, just fixed tabs/spacing to make more readable]]

<<liveblock>> and <<update>> macros don’t seem to be documented in Sugarcube’s documentation.. At this point, without knowing how these macros work, I’m not sure how to help you.

Anyway, I may offer two points.

First it looks like your code doesn’t allow to add a point in characteristics already higher than the remaining points to add. This is precisely what means $strengthvalue lte $totalpts. You could replace the latter variable by whatever you want the maximum for a characteristic to be. Right now the player is already prevented to add points when there are none to spend anymore.

Also, your code doesn’t seem to prevent negative characteristic values.

1 Like

@kcmalik
You have a few <<</liveblock> with a missing > at the end. That probably would give you a few issue.

EDIT: @souppilouliouma is correct. The issue here comes from $var lte $totalpts. If you remove that part of code it will get to 0 no problem.
Here’s the edited coded below @kcmalik :
I’ve also removed the unnecessary liveblocks (only one is needed) and the empty elseif :wink:

<<liveblock>>
<<link "<-">>
    <<set $strengthvalue -= 1>>
    <<set $totalpts += 1>>
    <<update>>
<</link>>

$strengthvalue

    <<if $totalpts gt 0>>
            <<link "->">>
                <<set $strengthvalue += 1>><<set $totalpts -= 1>>
                <<update>>
            <</link>>
    <</if>>

<<link "<-">>
    <<set $luckvalue -= 1>>
    <<set $totalpts += 1>>
    <<update>>
<</link>>

$luckvalue

    <<if $totalpts gt 0>>
        <<link "->">>
            <<set $luckvalue += 1>>
            <<set $totalpts -= 1>>
            <<update>>
        <</link>>
    <</if>>


<<link "<-">>
    <<set $intvalue -= 1>>
    <<set $totalpts += 1>>
    <<update>>
<</link>>

$intvalue

    <<if $totalpts gt 0>>
        <<link "->">>
            <<set $intvalue += 1>><<set $totalpts -= 1>>
            <<update>>
        <</link>>
    <</if>>


$totalpts<</liveblock>>

To take care to avoid the negatives, you can wrap the <- links with:
<<if $statvar gt 0>> <</if>>
The link will disappear if the stat reaches 0.

Hope this heelps~~

Because they are a custom macro (from Cycy, and iirc from the Twine server, it should be added to the next update??? Edit: it’s going to be something similar, oops). They essentially do a <<replace>> and update variable without changing pages/using the <<replace>> macro.

2 Likes

The Live Update macro set is not going to be added to SugarCube.

A similar set of macros—<<do>><</do>> and <<redo>>—will be in the next release, however, so you were close.

1 Like

Thank you @manonamora and @TheMadExile for the explanations.

1 Like