How do I set variables conditionally based on previous choices?

I want a variable like ‘tall’ to mean something like ‘*set var -10’, unless you have previously chosen a variable like ‘attractive’, and then choosing that variable ‘tall’, sets ‘*set var’ to +10. I didn’t see any info on this anywhere.

*choice 
....#Be tall.
........*set var "tall"

When you need to change the numeric value.


*if (var = "tall")
....*if not  (attractive)
........*set variable - 10
....*if (attractive)
........*set variable + 10

Another way to do this is

*if (var = "tall") and (attractive)
....*set variable + 10
....*goto next_part
*else
....*set variable - 10
....*goto next_part

Here I am assuming that the tall variable is a string, the attractive variable is boolean and the “variable” variable is a numeric value.

You can read more about *if on this wiki page.

Hope this helps!

3 Likes

ok so, i have two choices #beautiful and #pretty
choosing beautiful gets you a social 20% boost and tall an additonal 10%. problem is choosing #pretty and then #tall should decrease social score by 10% but it stays the same
#Tall
tall
*set var true
*if (var = “tall”)
*if not (beautiful = true)
*set social -10
*if (beautiful = true)
*set social +10
what am i doing wrong?

So you made “tall” string (text variable) and then made a new variable called “var” as boolean (variables which are either true or false) but in the fourth line you are applying it as a string, that’s one problem.

If your variable is not a string then you don’t need to do the ( = " " ) thing. You can just do *if (beautiful), but if your variable is a string then you would do the ( = " " ) thing.

Here is my attempt at doing it.

What is your height?
*choice
..#Tall
....*set height "tall" (this variable is a string)
....*goto next_part
..#Short
....*set height "short"
....*goto next_part

*label next_part
So are you beautiful or just pretty?
*choice
..#Beautiful
....*set beautiful true (this variable is a boolean)
....*goto part2
..#Pretty
....*set beautiful false (sidenote: if you created this variable as false then you don't need to set it again)
....*goto part2

*label part2
*if (height = "tall")
..*if (beautiful)
....*set social + 10
..*if not (beautiful)
....*set social - 10

An important thing to remember is that if you created a variable as a string then it would remain a string, a boolean would stay a boolean and a numeric variable would stay as a numeric variable.

In short, you can’t change the nature of a variable midway.

5 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.