Page 1 of 1

Client side include for JS.

Posted: 17 April 2020, 15:22
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

Re: Client side include for JS.

Posted: 18 April 2020, 02:55
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, {

Re: Client side include for JS.

Posted: 18 April 2020, 11:30
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

Re: Client side include for JS.

Posted: 14 February 2021, 22:11
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 :-)

Re: Client side include for JS.

Posted: 15 February 2021, 10:06
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 :)

Re: Client side include for JS.

Posted: 15 February 2021, 10:56
by JochenZ
OK :-) I add it today after work :-)