# Simultaneous (nested) AniSequences

**URL:** <https://discourse.processing.org/t/simultaneous-nested-anisequences/14380>\
**Category:** Libraries\
**Created:** [October 2, 2019, 11:55pm UTC](https://discourse.processing.org/t/simultaneous-nested-anisequences/14380 "2019-10-02T23:55:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo.nerd](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leo.nerd/32/6101_2.png) [@leo.nerd](https://discourse.processing.org/u/leo.nerd)\
**Post date:** [October 2, 2019, 11:55pm UTC](https://discourse.processing.org/t/simultaneous-nested-anisequences/14380/1 "2019-10-02T23:55:57Z")

</div>

Hello. I’m trying to use the Ani library to orchestrate a sketch that contains several “sub-modes” that have their own timelines and display methods. Essentially, I would like the master sketch to run a sequence similar to:

- Do some intro stuff

- Mode 1 plays: start its own sequence, reach the end

- Do some transition stuff

- Mode 2 plays: start its own sequence, reach the end

- Do some outro stuff

The “modes” being their own classes with their own display() methods that are called by the master `draw()` when necessary. There are several “modes” but for the sake of minimal reproducible error here I’m showing only one `Mode` class.

I’m successfully running an `AniSequence` inside my `Mode` class but I get this error: `### Ani Debug -> Error @ AniCore -> dispatchOnFinish(). java.lang.reflect.InvocationTargetException`  
as the Mode’s own sequence reaches its end and tries to tell the master `AniSequence` to `resume()`.

Any ideas?  
Thank you very much!  
See code below:

```auto
import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;
Mode mode1;
AniSequence score;
int foo;

void setup() {
  Ani.init(this);
  size(1000, 500);
  score = new AniSequence(this);
  foo = 0;
  mode1 = new Mode(this, score);
  
  score.beginSequence();
  //do one first step, then start mode1
  score.add(Ani.to(this, 1, "foo", 255, Ani.LINEAR, mode1, "onEnd:enter"));
  // and pause the master score.
  score.add(Ani.to(this, 1, "foo", 255, Ani.LINEAR, "onStart:pauseMasterScore"));
  //when master score is resumed do this
  score.add(Ani.to(this, 2, "foo", 0, Ani.LINEAR));
  score.endSequence();
  score.start();
}

void draw() {
  background(0);
  println("master score step = ", score.getStepNumber());
  mode1.display();
}

void loop() {
  score.start();
}

void pauseMasterScore() {
  score.pause();
  println("##################### MASTER SCORE PAUSED");
}

class Mode {
  AniSequence mScore;
  AniSequence mParentScore;
  int mPos = 0;

  Mode(PApplet _p, AniSequence _ps) {
    mParentScore = _ps;
    mScore = new AniSequence(_p);
    mScore.beginSequence();
    mScore.add(Ani.to(this, 2, "mPos", 50, Ani.LINEAR, "onEnd:resumeMasterScore")); //do something then resume the master score
    mScore.endSequence();
  }

  void enter() {
    mScore.start();
    println("##################### SUB SCORE STARTED");
  }

  void display() {
    println("sub score step ", mScore.getStepNumber());
    fill(150, 0, 0);
    rect(mPos, mPos, 100, 100);
  }
  void resumeMasterScore() {
    mParentScore.resume();
    println("master score resumed");
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 3, 2019, 1:51am UTC](https://discourse.processing.org/t/simultaneous-nested-anisequences/14380/2 "2019-10-03T01:51:54Z")

</div>

i think the program structure is ok,

just the .resume() is bad,  
as when i use .pause() instead i not get a error.

( both not make sense for me, and i never used that library / and in a class / with nested structure /  
so i not know what i am talking about )
