0 votes
by (230 points)


I've been struggling for a long time to solve this and I still can't find any solution.

I made a mini games in p5 that I want to be displayed in my twine story (wrote in Sugarcube 2-21).

But the tricky part is that I want my mini game to occur in different passages with few different paramters, like for exemple, with an increased difficulty.

Is there a way to call in a passage a function from a p5 sketche in the javascript section ?

I made an exemple to make myself clear:

Here is an extremly simplified code for the game in the javascript section of my story :

setup.p5promise = importScripts([

setup.myGame = function (game) {

  game.createGame = function(difficulty) {

    //here I create the canvas with the difficulty parameters

    if      (difficulty == 1) game.background(117,255,204);
    else if (difficulty == 2) game.background(252,130,255);


  game.draw = function() {

    //here is the game




Here is the way I would like to call the game in my story


  // here I call a function in my previous script that launch the game with parameters

  // like game.createGame(1);
  // or   game.createGame(2);



Please log in or register to answer this question.