Client side include for JS.

Game development with Board Game Arena Studio
Post Reply
User avatar
Lunalol
Posts: 584
Joined: 09 October 2016, 23:21

Client side include for JS.

Post by Lunalol »

Hi, all.

In PHP (server side) we can include files stored in module directory : "require_once( 'modules/something.php' );"

What can we do on client side if JS source file getting bigger and bigger.
Can we use dojo to create a module ?

My file is near 1000 lines long (and it's only the beginning), for diceforce it's near 5000 !

Thanks.
PJL
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Client side include for JS.

Post by Victoria_La »

You put the in modules too, see example here
https://github.com/elaskavaia/bga-sharedcode

This is sample project it has another js defined
https://github.com/elaskavaia/bga-share ... dparent.js

This has bunch of globals it also defines a class bgagame.sharedparent which I use as parent in my game
like this

Code: Select all

define([ "dojo", "dojo/_base/declare", "ebg/core/gamegui", "ebg/counter",
    // load my own module!!!
    g_gamethemeurl + "modules/sharedparent.js" ], function(dojo,
        declare) {
    return declare("bgagame.mygame", bgagame.sharedparent, {
User avatar
Lunalol
Posts: 584
Joined: 09 October 2016, 23:21

Re: Client side include for JS.

Post by Lunalol »

Thanks great !

I already tried this but I dont' use "g_gamethemeurl" ( I did not know it existed), so module not found error !

PJL
User avatar
JochenZ
Posts: 2
Joined: 07 February 2021, 12:50

Re: Client side include for JS.

Post by JochenZ »

I am late for this, but I have just registered ;-)

You can include your own scripts like this:

Code: Select all

define([
  "dojo","dojo/_base/declare",
  "bgagame/modules/yourinclude",
    "ebg/core/gamegui",
    "ebg/counter"
],
function (dojo, declare, yourinclude) {
});
Note the third input parameter "yourinclude" beside dojo and declare.

You put yourinclude.js in your modules directory.

yourinclude.js should look like this:

Code: Select all

define([], function() {
	return "TEST";
});
In the array you can define further dependencies, for example "ebg/stock".
The return value of the function is then the value of the third input parameter as defined above.
Of course it does not has to be an string, it can be an array, an object, an function, something you declared with dojo declare and so on.

This way you can easily structure your javascript files and include them in the main game javascript file.

zet :-)
User avatar
thoun
Posts: 1621
Joined: 10 December 2020, 22:25

Re: Client side include for JS.

Post by thoun »

JochenZ wrote: 14 February 2021, 22:11 yourinclude.js should look like this:
Can you add it to https://en.doc.boardgamearena.com/BGA_S ... ipt_module please ?
Wiki article is not complete, you have more informations :)
User avatar
JochenZ
Posts: 2
Joined: 07 February 2021, 12:50

Re: Client side include for JS.

Post by JochenZ »

OK :-) I add it today after work :-)
Post Reply

Return to “Developers”