# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [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/1 "2020-09-17T04:15:29Z")

</div>

```auto
//Variables
	//Character Stat and Detail Variables
		//Character Details
			var Character_Name = [""];
			var Age = [""];
			var Alignment = [""];
			var Religion = [""];
			var Background = [""];
			var Hair = [""];
			var Race = [""];
			var Height = [""];
			var Gender = [""];
			var Size = [""];
			var Weight = [""];
		//Character Stats
			var Health = [""];
			var Stamina = [""];
			var Mana = [""];
			var Strength = [""];
			var Dexterity = [""];
			var Agility = [""];
			var Constitution = [""];
			var Endurance = [""];
			var Fighting = [""];
			var Intelligence = [""];
			var Psyche = [""];
			var Wisdom = [""];
			var Intuition = [""];
			var Reason = [""];
			var Charisma = [""];
			var Physical_Beauty = [""];
		//Character Abilities
			var Spells = [""];
			var Skills = [""];
			var Abilities = [""];
			var Talents = [""];
			var Special_Abilities = [""];
			var Ultimate_Talents = [""];
		//Character Inventory
			var Inventory = [""];
	//Item Variables 
		//Character Items
			var Weapon_Tool_Names = ["Basic Wand, Basic Staff, "];
			var Spell_Names = [""];
			var Skill_Names = [""];
			var Ability_Names = [""];
			var Talent_Names = [""];
			var Special_Ability_Names = [""];
			var Ultimate_Talent_Names = [""];
		//Quest Items
			var Quest_Items
	//Story Variables
		var Title = ["Untold Magius"];
		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"];
		var Quests = ["A barren mind"];
			//Unused quest names
				//Awakening
				//Beginnings
				//Memories
				//Shadows of the past
				//Beach of mystery
				//A forgotten past
				//Land/Beach of questions
				//Questioning sands
				//World of lost beginnings
				//Beach of unknown pasts
				//A snake in our midst
				//Jungles of time
				//A future unseen
		var CurrentArea = ("StarterBeach");
		var Areas = ("StarterBeach");
		//Map link? or maybe make an interactive map that auto updates later on in the game?
//Setup
	//Main Canvas Setup
		function setup()
		{
			createCanvas(600,600);
			background(0);
			input = createInput();
			input.position(210,500);
			input.size(200);
			button = createButton("submit");
			button.position(430,501);
		}
	//Text Control and Game Coloring
		function draw()
		{
			fill(190);
			rect(-1,-1,600,50);
			fill(150);
			rect(-1,50,600,600);
			drawTitle(width * 0.5);
			drawStory(width * 0.015);
		}
	//Title Text
		function drawTitle(x)
		{
			textAlign(CENTER);
			textSize(45);
			fill(0);
			text(Title, x, 36);
		}
	//Story Text
		function drawStory(x)
		{
			textAlign(LEFT);
			textSize(20);
			fill(0);
			text(Story, x, 75);
		}
//Game Logic
	function handleInput()
	{
		//Finds out what you type into the text box and turns it into a variable the game can read
		var inputValue = input.value();
		
		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");
		}
	}

```

I am trying to get my game to read what you have typed into the text box at the bottom when you press submit, then clear the text box and adjust the story depending on what you have typed, but it is refusing to change the Story variable I think? Any help would be appreciated.

---

<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, 4:10pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/2 "2020-09-17T16:10:03Z")

</div>

> [@DariusKempton](#):
>
> `inputValue == "A"`

You can‘t check a String with ==

instead use

inputValue.equals(„text“)…

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 4:12pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/3 "2020-09-17T16:12:51Z")

</div>

ohhh okay, thanks again for the help, i will go try that now

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 4:16pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/4 "2020-09-17T16:16:04Z")

</div>

i tried that, but it is still not reacting or doing anything… am i missing some part of the code that i need to tell the game what to do when the submit button is pressed?

---

<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, 6:52pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/5 "2020-09-17T18:52:44Z")

</div>

> [@DariusKempton](#):
>
> `handleInput()`

Do you call this from  
draw()?

I think you should

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 7:10pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/6 "2020-09-17T19:10:52Z")

</div>

you mean have the handleInput() function within a draw() function?  
so  
function draw()  
{  
function handleInput()  
{  
}  
}

---

<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, 7:11pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/7 "2020-09-17T19:11:48Z")

</div>

No.

Just call it as you call drawTitle()

We always make assumptions about what processing does in a sketch.

At the Moment the assumptions are wrong. To verify the assumptions you can use println („here 1“);

Sorry, my phone kills the “”

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 7:15pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/8 "2020-09-17T19:15:56Z")

</div>

what do you mean by call? can you give me an example? i havent ever really learned to code from anyone and p5.js is still new to me

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 7:16pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/9 "2020-09-17T19:16:27Z")

</div>

its always just been me trying to figure things out on my own

---

<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, 7:51pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/10 "2020-09-17T19:51:01Z")

</div>

> [@DariusKempton](#):
>
> ```auto
> function draw()
> {
> fill(190);
> rect(-1,-1,600,50);
> fill(150);
> rect(-1,50,600,600);
> drawTitle(width * 0.5);
> drawStory(width * 0.015);
> }
> 
> ```

Here add

> [@DariusKempton](#):
>
> ```auto
> function draw()
> {
> fill(190);
> rect(-1,-1,600,50);
> fill(150);
> rect(-1,50,600,600);
> drawTitle(width * 0.5);
> drawStory(width * 0.015);
> handleInput();
> }
> 
> ```

Just the last line

That’s calling the function

Otherwise it’s not executed/ run by processing

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 7:52pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/11 "2020-09-17T19:52:48Z")

</div>

so i should just add handleInput(); into that draw function and it tells the game to check it?

---

<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, 8:23pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/12 "2020-09-17T20:23:18Z")

</div>

Yeah, without calling the function it is ignored

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 8:30pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/13 "2020-09-17T20:30:50Z")

</div>

alright, thanks, its working now, although it instantly submits whatever you type soon as it matches the requirements of the ‘if’ section of the code

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 8:31pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/14 "2020-09-17T20:31:22Z")

</div>

so im probably going to forego the submit button if it works without it

---

<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, 8:52pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/15 "2020-09-17T20:52:53Z")

</div>

You can also send the input just when you click the submit button or hit return/enter

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 8:54pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/16 "2020-09-17T20:54:36Z")

</div>

well, the way it is right now, as soon as whatever you type into the text box meets one of the requirements for the if/else if parts, it activates them, which is bad, cause then whenever the game starts, it brings me straight to the error page that i made for when you dont type anything into the text box

---

<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, 8:59pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/17 "2020-09-17T20:59:01Z")

</div>

I see

can you call handleInput not in draw but when the submit button is hit

(sorry I don’t know p5.js)

Warm regards,

Chrisir

---

<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:02pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/18 "2020-09-17T21:02:59Z")

</div>

I think here:

> **[reference | p5.js](https://p5js.org/reference/#/p5/createButton)**

you tell the button which function to run

in the reference it’s

```auto
  button.mousePressed(changeBG);

```

you could say

```auto
  button.mousePressed(handleInput);

```

---

<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:03pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/19 "2020-09-17T21:03:39Z")

</div>

and remove `handleInput` from draw() please

Chrisir

---

<div class="post-metadata">

**Author:** ![DariusKempton](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DariusKempton](https://discourse.processing.org/u/DariusKempton)\
**Post date:** [September 17, 2020, 9:25pm UTC](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910/20 "2020-09-17T21:25:09Z")

</div>

i figured out how to get the submit button working, and changed the error page to a simple error message

[Next page](https://discourse.processing.org/t/help-with-using-input-values-with-variables-along-with-if-else-if-code/23910.md?page=2)
