Running code when the project is paused (Solved)

So I have somewhat found a way to run code when the project is paused, the issue is that it doesn’t work very well.

If you open a new wick project either by opening or reload the page, or by just clicking the “new” button create a single shape and stick the below code into the frame then the shapes color will start changing. Then if you pause the project you should see that it doesn’t stop. But if you do anything to interact with it, it will then stop. This includes things like selecting the shape.

window.test = {};

test.objs = project._children[0]._children[0]._children[0]._children;
let obj = test.objs[0].view.item;
obj.fillColor = "red";

test.func = function () {
    this.fillColor.hue += 6;
};

test.func2 = function () {
    this.fillColor.hue += 1;
};

// chnage the below test.func into test.func2 and it stops working...
obj.onFrame = test.func;

The issue that I am facing is not so much to do with it not being selectable but rather that if you do anything to the line in the above code obj.onFrame = test.func; to obj.onFrame = test.func2; after playing the project once, which should change which function the path object is executing every frame, it instead just stops doing anything at all and from what I tested. Even if you delete that shape make a new one and then run the project again, still does nothing. Or if you just remove that line of code and run the project again it will also stop.

This is the about the onFrame variable http://paperjs.org/reference/path/#onframe

Here is a example project of it that hasn’t been run yet My Project1-26-2022_20-28-15.wick (1.5 KB)

So I have fixed both issues, now you can interact with the object itself and you can change the function that it runs. I simply stuck the path that I would execute the code from inside of a clip and then it works fine. It will only stop working if you go into the clip and interact with the path.

My Project1-27-2022_12-07-07.wick (1.7 KB)

This example wick file will have the shapes color constantly changing unless the mouse is hovering over it, and it works when the project is paused.

Note: it also will run independent of the project’s framerate

1 Like