Locking in variables

Let’s start with what I try to do. When a variable reaches a certain number I would like it to lock in. So, let’s assume this:

$stat1 is “3”
$stat2 is “1”

Upon a variable reaching number 3 I would like the other one to stop going up. Do I change the variable type from a numer to a boolean, so $stat1 becomes “true” making it locked in? It seemed like a good idea but then again the choices to level up the variable are still present so how do I tell Twine to stop counting them? :pensive:

I was thinking about a way of keeping track of which stat goes up to 3 first and kind of keep the other one down to 0 but without knowing which one gets there first makes it tricky. I just have no idea how to do it? Would appreciate a clue.

I’m using:
Twine Version: 2.3.14
Story Format: Sugarcube 2.34.1

Without your code we can only guess what you’re really trying.
However my best idea is every time you modify $stat1 or $stat2, you can add an <<if>> <</if>> clause.

Example: some action may allow an increase of $stat2, only if $stat1 isn’t already at 3.

Given $stat1 and $stat2

<<if $stat1 !=3>><<set $stat2 +=1>><</if>>
1 Like

This seems like a logical way of doing this…

I don’t have much of a code around the idea yet, just a couple of variables representing opposite stats:

$irritable and $patient for exaple, so I want one to lock when the reader reaches numer 3 on either of those two stats. In a link it goes like one would expect:

[[Option 1][$irritable +=1]]
[[Option 2][$patient +=1]]

So I imagine as certain point (when I will know it’s possible for the reader to actually reach those 3 points in a certain variable) I’ll have to hide links between:

<<if $irritable !=3>>[[Option 1]]<</if>>
<<if $irritable < 3>>[[Option 1][$patient +=1]]<</if>>
<<if $patient !=3>>[[Option 2]]<</if>>
<<if $patient < 3>>[[Option 2][$irritable +=1]]<</if>>

Am I on the right track here? :sweat_smile:

I’d use an <<else>> to guard against typos or mistakes where your two if statements don’t cover everything:

<<if $irritable < 3>>[[Option 1][$patient += 1]]
<<else>>[[Option 1]]
<</if>>
1 Like

One night to sleep on this, and I find my answer lacking: I don’t prevent the higher variable to go up further than 3.

<<if $irritable < 3 && $patient < 3>>[[Option 1][$patient += 1]]
[[Option 2][$irritable += 1]]
<<else>>[[Option 1]]
[[Option 2]]
<</if>>

Of course $irritable and $patient need to be and stay integers and to increase by only 1 at a time. If you plan either to allow fractions or to increase by more than one you would need to manually set a maximum to 3. It can be addressed with little more circonvoluted conditions. Example below.

<<if $irritable < 3 && $patient < 3>>
   <<link "Option 1" "Option 1">><<set $patient += 1>>
      <<if $patient gt 3>><<set $patient to 3>><</if>>
   <</link>>
   <<link "Option 2" "Option 2">><<set $irritable += 1>>
      <<if $irritable gt 3>><<set $irritable to 3>><</if>>
   <</link>>
<<else>>[[Option 1]]
[[Option 2]]
<</if>>
1 Like

I’ll play around with the code, thank you both very much for tossing in ideas how to tackle the problem :slight_smile: