rolandino Posted May 2, 2014 Share Posted May 2, 2014 Hi,Have a question re: codevinsky's rather wonderful "generator-phaser-official" (see http://codevinsky.ghost.io/phaser-tutorial-getting-started-with-generator-phaser-official/).If I generate a sample project (by running yo phaser-official) it generates a set of JS files in states, five .js files.What I'd like to know - is - in this structure where can I put global variables. For example, supposing I wanted to hold onto the level a game player is on and didn't wish to use local storage? I can't (and no doubt shouldn't) put it in main.js - that gets overwritten.So just wondered if anyone had any suggestions?Many thanks,R Link to comment Share on other sites More sharing options...
CtlAltDel Posted May 2, 2014 Share Posted May 2, 2014 make a small storage yourself. for instance make a file storage.js:var storage = {}module.exports = storage;And then just require it:var storage = require('storage');after that you can use it in that specific state/prefab/whatever to retrieve / store data:storage['omgpuppies'] = 'CUTE!';console.log(storage['omgpuppies']);Data stored is can be retrieved in other states etc due to the require call returning the same dict. This is the simplest example I could come up with. Link to comment Share on other sites More sharing options...
rolandino Posted May 3, 2014 Author Share Posted May 3, 2014 Hi CtlAltDel, That's great, many thanks. R Link to comment Share on other sites More sharing options...
mcuz Posted November 22, 2014 Share Posted November 22, 2014 i've tried this and it just doesn't worki create a global class in globals.js and use require in boot.js but it cannot be seen within game states Link to comment Share on other sites More sharing options...
CtlAltDel Posted November 22, 2014 Share Posted November 22, 2014 You have to require it in every state you need it. Or do something likegame.globalStorage = storage;And then reference it from your game. Link to comment Share on other sites More sharing options...
Recommended Posts