Jump to content

accessing variables from other source files?


DbD
 Share

Recommended Posts

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 like

public static game = *code here*

but that doesn't work with Phaser for some reason. Declaring it as

var game = *code here*

 

how can i access it in a different file?

Link to comment
Share on other sites

Have it be a function from a different file, like this:

 

MyExternalFunctions.js

function doSomethingElse() {  console.log("Doing something from another file!");}

Main.js

function 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...