How to load third party js library like underscore or lodash

Hi,

I want to add underscore to my game, but I'm not sure where to add the library, or what the best practice would be?

Ps. I'm not getting my confirm email, and I tried to send it a couple of times already, and I checked junk mail.
Has invited:

weism

Favor from: Morabaraba

Try to put the javascript files in the 'Scripts' folder.

eric

Favor from: Morabaraba

You should run the game in preview then you can test window.** on console.
If you play game in Editor, then the game is running the a iframe.

eric

Favor from: Morabaraba

For debugging you can you use:
var win = G.game.getWindow()
 
 

Morabaraba - A ancient African game

Favor from:

Thanks, it works.
 
This is more a js question but why can I not assign to the window object in the awake scope? Is it using "strict on", or some other witchery! See the image at <snip forum does not allow url /> for my Behaviour class.
 
```js
// define a user behaviour
var ArenaClock = qc.defineBehaviour('qc.engine.ArenaClock', qc.Behaviour, function() {
    // need this behaviour be scheduled in editor
    console.log('defineBehaviour', arguments, this);
    this.runInEditor = true;
    
    this.tick = 5000;
    this.lastTick = this.tick;
    
}, {
    // fields need to be serialized
    tick : qc.Serializer.INT 
});

// Called when the script instance is being loaded.
ArenaClock.prototype.awake = function() {
    console.log('Setting up timer', this.tick);
    var self = this;
    this.timer = this.game.timer.loop(this.tick, function() {
        console.log('Timer trigger', arguments, this);
        console.log('underscore', _.VERSION );
        // console log version number correctly as 4.0.1
        window.lodah = _;
        console.log('lodash', window.lodash);
        // console log undefined ?!?
        //debugger; // not happy 
    }, this);


};
```
 
lodash.min.js 4.0.1 was in my scripts file as recommened.
 
ps. you guys and girls rock!

eric

Favor from:

window.loda(s)h = _; you are missing 's' 
console.log('lodash', window.lodash);

Morabaraba - A ancient African game

Favor from:

*Eish*, Thanks for pointing it out.
 
But I still don't see those var on my window scope in chrome dev console. I can see the timer knock off, but when I then try to access `window.lodash` it return undefined.
 
 

Morabaraba - A ancient African game

Favor from:

Thanks, thought it was somethling like that.
 
is the iframe id static? because I want to do something like:

var check = document.getElementById("iframeid").contentWindow.a;
 

To reply to a question, please Login or registered