How do I call this function with a button?

I have the following JavaScript that runs when my game board loads:

if (runtimeScene.getTimeManager().isFirstFrame()) {
    // Iterate through all objects of type "Sprocket" on the "Sprockets" layer
    const sprockets = runtimeScene.getObjects('Sprocket');

    // Loop through each object and set a random rotation angle
    for (let i = 0; i < sprockets.length; ++i) {
        // Set a random rotation angle (0, 90, 180, or 270 degrees)
        const randomRotation = Math.floor(Math.random() * 4) * 90;
        sprockets[i].setAngle(randomRotation);
    }
}

The purpose is to randomize the angles the sprockets appear on the board. I’d like to be able to call that function when the player taps a button called “BtnResetScenario”, so they can randomize the board again. Currently, the button just reloads the screen, which works, but I think it would be a more efficient to just have the button call the function.

Anybody know how to do that with a button “BtnResetScenario”?

Hi, I found an old topic with your problem check this out

Based on that topic the above image may be the result.

Yeah, I had been trying to do it the hard way, hehe. I’ve got it working now. Thanks!