Delaying function blocks?

Hi there, I am very very new to processing.

I have created 4 different function blocks. Is there a way to have one function run for 3 seconds, and then switch to the next function for 3 seconds, etc, etc? when I put them all in the draw block, they all overlap so I need some sort of delay between functions.

Thanks so much!!

int cur = int((millis()%12000)/3000);
if(cur == 0) A();
if(cur == 1) B();
if(cur == 2) C();
if(cur == 3) D();
1 Like

Thank you so so much! If I wanted to add a “if key pressed…freeze this function and start new function”, would you happen to know how to do that? each function is just a drawing of shapes. I just want the shape to stay when key pressed, and then start new function where shape can stay when key pressed.

do you mean

while key pressed

or

after key pressed

oops, sorry I meant after I press a key and release it, I want it to keep the drawing on the screen until i stop it!

that is without your timer…
just a ?scene?level?

int screen = 0;

void setup() {
}
void draw() {
  switch (screen) {
  case 0:
    background(255);
// show shape a
    break;
  case 1:
    background(200,200,0);
// show shape b
    break;
  case 2:
    background(0,200,200);
// show shape c
    break;
  case 3:
    background(200,0,200);
// show shape d
    break;
  }
}
void keyPressed() {
  if ( key == '0' ) screen = 0;
  if ( key == '1' ) screen = 1;
  if ( key == '2' ) screen = 2;
  if ( key == '3' ) screen = 3;
}

Hmm, maybe I am describing my issue poorly…I don’t think the above code would work in my case.

I have 4 different functions I want to run. Each function will cycle through 3 different shapes continuously until a key is pressed and released. When the key is pressed and released, whatever shape is on the screen will stay on the screen until the very end and the next function block will run. The next function block will also cycle through 3 other different shapes. Again, when key is pressed and released, whatever shape is on the screen will stay (there would be 2 shapes stuck on the screen now), etc, etc. So basically need to freeze a function, skip the rest of the block and start a new function when the key is pressed and released. It can be any key.

I appreciate all your help though, I really do!

possibly it would be much better if you show YOUR code here, so we can get a better idea.

This seems like a slot-machine. :slot_machine:
But only 1 shape is shown and chosen at a time. :thinking:

1 Like

Yes!!! Like a slot machine!!!

  • You should make a SlotShape class.
  • It should be responsible to display a PImage for some seconds (or frameCount) and change to next 1.
  • And stop changing the PImage objects when keyPressed() or mousePressed() is called back.

So I have the function displaying for some seconds and then switching to the next shape by using mills:

int m = (milliseconds()/1000)%10;

void shapesCategory1()
{
if (m < 3)
{
drawCircle();
}
if (m < 6)
{
drawSquare();
}
if (m < 9)
{
drawRectangle();
}

the only way I know how to stop this Is by saying:

boolean keySelect;
keySelect = false; (this is under void setup)

void keyPressed()
{
keySelect = !keySelect;
}

and then under each draw shape add:

if (keySelect)
{
drawCircle();
noLoop();
}

but then it just stops completely. Is there a function similar to noLoop() that will let me jump to a different function block when key is pressed so that I can select the next set of shapes in another function?

I would paste my code but it is SO messy and barely makes any sense to me right now lol