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

	//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
				//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?
	//Main Canvas Setup
		function setup()
			input = createInput();
			button = createButton("submit");
	//Text Control and Game Coloring
		function draw()
			drawTitle(width * 0.5);
			drawStory(width * 0.015);
	//Title Text
		function drawTitle(x)
			text(Title, x, 36);
	//Story Text
		function drawStory(x)
			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.");
		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.

You can‘t check a String with ==

instead use


1 Like

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

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?

Do you call this from

I think you should

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


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 “”

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

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

Here add

Just the last line

That’s calling the function

Otherwise it’s not executed/ run by processing

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

Yeah, without calling the function it is ignored

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

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

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

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

1 Like

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,


I think here:

you tell the button which function to run

in the reference it’s


you could say


and remove handleInput from draw() please


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

1 Like