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

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

Hello @laptophead,

A simple example:

// 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:

And lots of other options out there…

Have fun!

:)

1 Like
1 Like

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

1 Like