# How do I set variables conditionally based on previous choices?

**URL:** <https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234>\
**Category:** ChoiceScript Help\
**Created:** [September 18, 2021, 3:14pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234 "2021-09-18T15:14:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yev](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/yev/32/39606_2.png) [@Yev](https://forum.choiceofgames.com/u/Yev)\
**Post date:** [September 18, 2021, 3:14pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234/1 "2021-09-18T15:14:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RedEmperor](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/redemperor/32/147485_2.png) [@RedEmperor](https://forum.choiceofgames.com/u/RedEmperor)\
**Post date:** [September 18, 2021, 3:28pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234/2 "2021-09-18T15:28:12Z")

</div>

```
*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](https://choicescriptdev.fandom.com/wiki/If).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Yev](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/yev/32/39606_2.png) [@Yev](https://forum.choiceofgames.com/u/Yev)\
**Post date:** [September 18, 2021, 4:41pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234/3 "2021-09-18T16:41:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RedEmperor](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/redemperor/32/147485_2.png) [@RedEmperor](https://forum.choiceofgames.com/u/RedEmperor)\
**Post date:** [September 18, 2021, 5:59pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234/4 "2021-09-18T17:59:02Z")

</div>

> [@Yev](#):
>
> #Tall  
> tall  
> \*set var true  
> \*if (var = “tall”)

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.

> [@Yev](#):
>
> \*if not (beautiful = true)

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.

```choicescript
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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/choiceofgames/original/3X/e/f/efe1497a762edecdb6d569a1c4abee87508bf002.png) [@system](https://forum.choiceofgames.com/u/system)\
**Post date:** [September 19, 2021, 6:00pm UTC](https://forum.choiceofgames.com/t/how-do-i-set-variables-conditionally-based-on-previous-choices/107234/5 "2021-09-19T18:00:00Z")

</div>

Closed on September 19, 2021, 6:00pm UTC

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