CodingTrain / Suggestion-Box

A repo to track ideas for topics
572 stars 86 forks source link

Text input issue #1241

Open juliamariee opened 5 years ago

juliamariee commented 5 years ago

I made this program in p5.js that does my math project for me and I want to make it so the variables are changed based on an input in a text box so its easier for someone else to use. (its called the angry birds project, hence the variables are named "bird" and "pig"). I have a bit of code commented out from my attempt at making the text inputs but it wasn't working. Also, I know my code is ugly and convoluted, but I only started learning a week ago so please be nice! :)

Here is the p5.js sketch that I have been working on: https://editor.p5js.org/julia.maiolo@gmail.com/sketches/bZR8Mzx6S

MrWe commented 5 years ago

I'm i bit unsure what exactly your problem is, but you're querying the value of the field inside your setup (when the user hasen't entered a value yet):

var birdyx = int(birdsx.value());

If you want to query the value continuously, either put that that line inside your draw loop, or even better, use an event listener (https://editor.p5js.org/michaelblum/sketches/Hkhl1QEA-).

You will also have to check if what is entered is a number so that it can be converted to an integer, code for that can be found here: https://www.mkyong.com/javascript/check-if-variable-is-a-number-in-javascript/ .

Welcome to coding!