This is a documentation for Board Game Arena: play board games online !

User talk:SwHawk/Create Modular Code

From Board Game Arena
Jump to navigation Jump to search

Please sign your comments using this syntax -- ~~~~ so that I may credit your additions to the article.

User names

"Tisaac Human Expert" -> Tisaac

"VictoriaLia" -> VictoriaLa

-- Mogri (talk) 18:08, 14 June 2022 (CEST)

Thanks for the corrections -- SwHawk (talk) 19:45, 14 June 2022 (CEST)

A non-dojo JS approach

Dojo is old and kinda bad. This approach lets you avoid Dojo and this and allows more modern JS.

window.X = {}; // X = your game, or you can use something more generic


setup: function (gameData) { // this cannot be an arrow function due to dojo
   X = Object.assign(this, X);
   // the rest of your setup goes here
X = Object.assign(X, {

  myFunction: (arg1, arg2) => {
    return arg1 + arg2;

  someFunction: (x) => _('The answer is: ') + x,

Notes on this approach:

  • Aside from setup and any framework-override functions, you should be using arrow functions
  • Always use X instead of this
  • As usual, you can use any number of modules this way

-- Mogri (talk) 18:08, 14 June 2022 (CEST)

While I agree that most of the components of the framework (be it PHP or JS) are old, there are some advantages to using its loader: dependencies management for instance. Also I'm not sure that changing every function definition to an arrow function offers better readability but that's a personal opinion, as I'm more used to languages where function keywords exists. -- SwHawk (talk) 19:45, 14 June 2022 (CEST)

Highlight lines added in code blocks

The code blocks are rather long right now with all of the comments, however I do think it is worth keeping them so they look like the starter files.

You could consider coloring or emphasising the lines added in some way.


 * BGA framework: © Gregory Isabelli <> & Emmanuel Colin <>
 * X implementation : © <Your name here> <Your email address here>
 * This code has been produced on the BGA studio platform for use on
 * See!doc/Studio for more information.
 * -----
 * This is the main file for your game logic.
 * In this PHP file, you are going to defines the rules of the game.

require_once 'modules/UtilityFunctionsTrait.php'; //Here we require the trait to be loaded when the class is loaded

use YourProjectNamespace\Modules\UtilityFunctionsTrait; //We import the trait to be used directly as UtilityFunctionsTraits, otherwise we would have to use the Fully qualified  class name (YourProjectNamespace\Modules\UtilityFunctionsTrait)

class YourProjectName extends Table

//////////// Utility functions

       In this space, you can put any utility methods useful for your game logic

   use UtilityFunctionsTrait; //Here we actually include the trait inside the class, making all the trait's methods available as class methods, keeping their visibility scope (so a private method is still private)

-- Thenmal (Thenmal) 19:04, 14 June 2022 (CEST)

Well thanks for that, I looked into the formatting guide, but I must have overlooked that part, thanks for showing me how to do it! -- SwHawk (talk) 19:45, 14 June 2022 (CEST)