# Help with using input values with variables along with if, else if code

**URL:** <https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910>\
**Category:** Coding Questions\
**Created:** [September 17, 2020, 4:15am UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910 "2020-09-17T04:15:28Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 17, 2020, 9:27pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/21 "2020-09-17T21:27:50Z")

</div>

I think you plan a kind of text adventure.

That’s very nice!

You might want to read the Wikipedia article about this.

I want to mention something:

You start here:

```auto
var Story =
["You wake up with the sun shining in your eyes. \nWhat do you do? \n\nA.Stand up \nB.Sit up \nC.Check yourself for injuries" 
];

```

Then you evaluate this

```auto
if (CurrentArea == "StarterBeach" && inputValue == "A")

		{
			Story("You stand up, and look around.");
			input.value("");
		}

		else if (CurrentArea == "StarterBeach;")
		{

			Story("Please type an answer into the box at the bottom and click the submit button");

		}

```

So after he chose A, B or C he / she is on anther screen (3 other screens in fact).

There he has to choose again A,B, C (for each of the 3 screens).

And again. And again. So it’s a big tree.

Your way to go there with if will lead into confusion. Try it out for a few hours. Good luck.

**Idea**

The reason is basically that you mix your data (your text) with the program logic (your ifs and elses).

It is wise to separate data and program logic.

Can you think of a data structure to help you with that?

I will suggest this:

**Data structure:**

Each sentence has a line number. Each sentence has 2 or 3 options to choose from. These lead in turn to (the line number of) new sentences.

**program logic**

You have ONE variable holding the current line number. Depending on the choosing of the user, we change the line number to the new line number and show the new sentence (for the new line number) and its 2-3 options.

**Example**

You can for each screen have ONE String in an array.

You can use the command split() to split at “#”. You get an arrayOneLine

Now the first item in arrayOneLine is the line number. The 2nd choice one. The 3rd line number to go to when choise one has been selected and so on:

```auto

"0#You wake up with the sun shining in your eyes. \nWhat do you do?# A.Stand up #1#B.Sit up #2#C.Check yourself for injuries#3"
"1#"You stand up, and look around.#....#4#....#5#"

```

(or simplify:  
`"0#Text \nwith choices\n.....#target line number 1#target line number 2#target line number 3"`

)

**See**

> [@Creating game dialogue](https://discourse.processing.org/t/creating-game-dialogue/23594):
>
> Hi I am in the process of developing my first game. It is an adventure platformer comprised of various missions that lead you to the overall objective (growing a flower). I am currently trying to develop a system to implement dialogue, however, I have not found many resources online specific to P5. Trying to follow tutorials in Java and C# is rather confusing as I do not have much experience with those languages and they also include functions not available to P5. I guess my question is where …

---

_[View the full topic](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910)._
