# I am trying to input a couple of variables at the sketch startup

**URL:** <https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558>\
**Category:** Coding Questions\
**Created:** [March 4, 2022, 4:56pm UTC](https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558 "2022-03-04T16:56:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [March 4, 2022, 4:56pm UTC](https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558/1 "2022-03-04T16:56:17Z")

</div>

Is there an example out there?  
Looked in the library… found nothing…  
So when the sketch starts, the user is prompted to input Month and Year in 2 different boxes.  
The values would have to be restricted to 1-12 and 2000 to 2030  
An "Invalid input " message would have to appear.

Then I would have an “Continue” button and those values would be retained in my sketch and put to work.  
Did someone do this before?  
Thanks  
Mitch

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 4, 2022, 11:09pm UTC](https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558/2 "2022-03-04T23:09:27Z")

</div>

Hello @laptophead,

A simple example:

```auto
// Set Initial Value
// v1.0.0
// GLV 2022-03-04

int value;

boolean set; //default is false

void setup()
  {
  size(100, 100);
  textAlign(CENTER, CENTER);
  textSize(48);  
  }
  
void draw()
  {
  background(0);  
  
  // if set = false
  if (!set)
    {
    fill(0, 255, 0);  
    textSize(48);  
    text(value, width/2, height/2-10);
    return;
    }
    
  // while set = true  
  fill(255, 0, 0);
  text(value, width/2, height/2-10);  
  }    
  
void keyPressed()
  {
  if(!set)
    {
    if (key == '+')
      value++;
    if (key == '-')
      value--;
    value = constrain(value, -10, 10);  
    println(value); 
    if (key == 's') 
      set = true;
    }    
  }

```

This is useful for a small range of numbers…

There is also:

> [@Open console instead of window](https://discourse.processing.org/t/open-console-instead-of-window/31040/8):
>
> Hello, There is always javax.swing.JOptionPane for simple IO: import javax.swing.JOptionPane; int col; void setup() { } void draw() { background(col); } void keyPressed() { thread("MessageDialog\_thread"); } void MessageDialog\_thread() { String strInp = JOptionPane.showInputDialog(null,"Enter a color 0 to 255:"); col = int(strInp); JOptionPane.showMessageDialog(null, col, "Output", JOptionPane.PLAIN\_MESSAGE); }slight_smile

And lots of other options out there…

Have fun!

`:)`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 4, 2022, 11:18pm UTC](https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558/3 "2022-03-04T23:18:18Z")

</div>

> <https://gist.github.com/GoToLoop/bba0c288aaeeb5ef9bb1>

---

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [March 9, 2022, 3:29am UTC](https://discourse.processing.org/t/i-am-trying-to-input-a-couple-of-variables-at-the-sketch-startup/35558/4 "2022-03-09T03:29:21Z")

</div>

Thanks everyone, that was a good point to start me up  
Mitch
