DbD Posted November 10, 2014 Share Posted November 10, 2014 Hi I was wandering how to use a variable called game in a differenct java file than it was declared in. I know in basic java I could use something likepublic static game = *code here*but that doesn't work with Phaser for some reason. Declaring it asvar game = *code here* how can i access it in a different file? Link to comment Share on other sites More sharing options...
Ham Posted November 11, 2014 Share Posted November 11, 2014 You are mixing Javascript with Java.if you are new to javascript you might want to take look at Javascript Scope var game = *code here* should be accessible in different files if you are defining it outside a function, if you still can't access it then take a look at loading order of the files, and check console for errors. Link to comment Share on other sites More sharing options...
DbD Posted November 11, 2014 Author Share Posted November 11, 2014 so say in my main file, i have something like this:function create() {code line 1code line 2} but i want to take code line 2, and put it into a different file. How would i go about this? Link to comment Share on other sites More sharing options...
lewster32 Posted November 11, 2014 Share Posted November 11, 2014 Have it be a function from a different file, like this: MyExternalFunctions.jsfunction doSomethingElse() { console.log("Doing something from another file!");}Main.jsfunction doSomething() { console.log("Doing something from the same file.");}function create() { doSomething(); doSomethingElse();}Then so long as both of these files are loaded, both functions will be called inside create. The best path from here is to try to limit what functions have access to by passing them the things they need to work on as parameters. This keeps code clean and modular. Link to comment Share on other sites More sharing options...
Recommended Posts