Skip to main content
Participating Frequently
May 28, 2019
Answered

Multiple games with same script on timeline

  • May 28, 2019
  • 2 replies
  • 871 views

I have an HTML5/js  project that contains the Main UI and four types of games (drag and drop;...etc) and a script for each type of game, that types will be repeated in the project 80 times.

To do that. I make  80 movieclips in the lib and copy/paste the script that corresponds to each type of game on the timeline..which results in a big js file with multiple repeated scripts.

Is there a best strategy for doing that?

    This topic has been closed for replies.
    Correct answer kglad

    no.

    among the several ways you could condense your js file is to create one function that encodes each game. put that function on frame one.

    pass the parameters (that vary from game to game) to that one function from the frames that contain your 80 games.  ie, use 80 function calls.

    2 replies

    avid_body16B8
    Legend
    May 28, 2019

    Seems to me that if you have several types of games, each type should be in a different function.

    This is what I do for example in the same fla if I have

    1- student inputs an answer in input field

    2- multiple-choice question

    3- drag n drop answer

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    May 28, 2019

    no.

    among the several ways you could condense your js file is to create one function that encodes each game. put that function on frame one.

    pass the parameters (that vary from game to game) to that one function from the frames that contain your 80 games.  ie, use 80 function calls.

    Legend
    May 28, 2019

    I'd be really surprised if each game is run by a single function.

    Wrapping each game's code up in a module would be the ideal solution.

    https://coryrylan.com/blog/javascript-module-pattern-basics

    kglad
    Community Expert
    Community Expert
    May 28, 2019

    the op stated, ".. a script for each type of game, that types will be repeated in the project 80 times."

    that's unclear (to me) but if it means the code is similar for each of the four types of games then my answer stands.  (except it might be easier and better to user four functions instead of one with one function for each game type.