#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# HELP PLEASE! :) New to Twine - Variables

Hello!

I am new to twine and not very familiar with programming at all. I am making a game for a class assignment and would love some assistance and/or advice.

I'm designing a game about drug addiction recovery with 4 variables (sobriety level, addiction status, methadone usage, and therapy status). Each variable has 3 possible values. Here are my questions about setting up these variables:

1. Should I set the variables to have numerical values of 1, 2, and 3, or can they operate on a gradient, such as 1-10, so that as the player moves through the game they gain or lose "points" that move them towards a particular value dependent on the choices they make?

2. How exactly do I program choices to effect variable value? For example, if the player chooses to go to therapy the variable of therapy status should shift to "in therapy." Where do you let twine know I want that to occur?

I'm sorry if I am not explaining things well or using inaccurate vocabulary; like I said, I am new to twine. If you have questions about my questions or my game, please express yourself!

• edited December 2015
Hi.

*** Made some edits cause I thought of more stuff.
Unfortunately, Twine 2 seems to use 3 or so different languages. So unless people know what you are writing in they may or may not be able to help. The answers I provided are for the Harlowe format.

1. You can use the variables on a gradient if you wish, but it will be a bit trickier.

If want a gradient, it might be that you have something like drinking builds DrunkPoints.
You could then do something like
(set: \$SobrietyLevel = "(if: \$DrunkPoints < 3)[Sober](if: \$DrunkPoints >3)[Buzzed](if: \$DrunkPoints >7)[Drunk])"

Whenever you add \$SobrietyLevel to a passage, it will check those three IF statements and display the appropriate one. You would need to write it all on one like that sicne sadly the Harlowe script does not allow for the { } symbols to remove white space in nested options.

2. In a story passage, just add a (Set: \$TherapyStatus = "In Therapy")
Elsewhere you could use \$TherapyStatus and it would display show the text.

As with the first answer warning, keep in mind that commands are run as they are found in the page. If you define \$TherapyStatus at the bottom of a page, the upper part of the page will know that it was set to something.

Other ways
Click functionality can be found in the official write up. http://twine2.neocities.org/
Setter links are only quasi supported in Twine 2 Harlowe.
Something like (Link: "Go to Therapy")[(set: \$TherapyStatus = "In Therapy")(goto: "Go to Therapy")] Will make it so players see a "Go to Therapy" blue link, and clicking it will send them to the Go to Therapy story passage while also setting \$TherapyStatus.
Using a link like this will NOT generate an arrow to the correct passage sadly.

You can work around this by doing something like
(if: \$arrowworkaroundhack > 0)[ Go to Therapy ]
Will cause an arrow to draw, but will also never appear in your story.

Anyway, with text based variables being set, you will likely want to have a list of pre-defined states for them when your story starts. This is handy to have in a separate passage somewhere so you can update it as needed.

If it's just a bunch of variables beings set, you could add a
(Display: "Starting Variables") to insert a passage called Starting Variables to any page.
Having something like this at the bottom of the first page can be helpful.

Would also recommend making a "Debug Variables" page, so that you can tweak whatever variables you want, and then just use Display to insert it into some page you are making dialogue for. Like if a character will say 3 different things, based on how sober you are, and so you want to debug starting on that passage.

Anyhoo, hope that helps.

• I'd be sticking with discrete variable values rather than trying to do gradients for your first foray into using variables. Makes things a little simpler.

Don't be afraid of inserting some print statements to shows the variables values - you can take them out later.

If your variable (say \$addiction) has 3 value (0, 1 and 2) you can set up other values to make the logic easier to process.
```<<set \$ADDICTION_CLEAR to 0>>
```

Then you would:
```<<set \$addiction to \$ADDICTION_CLEAR>>
```

and you can test it with:
```<<if \$addiction is \$ADDICTION_ADDICTED>> .... <<endif>>
```

Using the scheme you can also set up arrays to map the numbers to text for display.
```<<set \$ADDICT_TEXT to [ "Clear", "Addicted", "Cold Turkey" ]>>
```

This lets you
```<<print \$ADDICT_TEXT[\$addiction]>>
```

to display their current level of addiction as words.
• Thank you both for your help!!! It definitely clarified some things for me.

@mykael , I am wondering if by insert print statements you meaning having a text that tells player what their status is on each page, such as --> You are currently in withdrawal, in recovery, receiving methadone, and not in therapy.

To do that, would I use the <<print>> structure?
• Yeah, if you're using Twine 1 and Sugarcane (or SugarCube) format. The Harlow syntax will probably be different. Tried this tutorial? It's Twine 1.