0 votes
asked by (230 points)

Hi,

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([
  "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js",
  "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js",
  "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js"
]);

setup.myGame = function (game) {

  game.createGame = function(difficulty) {

    //here I create the canvas with the difficulty parameters

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

  };

  game.draw = function() {

    //here is the game

    game.fill(255);
    game.ellipse(game.mouseX,game.mouseY,10,10);

  };

};

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

<<script>>

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

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

<</script>>

 

Please log in or register to answer this question.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...