Jump to content

Any way to do re-usable code? (SOLVED)


Recommended Posts

Hi guys


I can't quite figure out how to do a global function in PandaJS.


I know you can add global variables by doing 'game.yourVariable', but can't seem to do the same with functions.


I've had a look at classes, but I'm not sure, they are what I need.


All I need is a reusable piece of code, that I can call later in any scene/level I choose.


I have a basic function working ...


game.nextLevel = function () {
        // Do something
But, what if I want to address variables that have not been declared yet?
The reason I ask is - I have a whole bunch of items I want to add at the start of each level.
Is there an easy way to lets say add all HUD items etc. without having to recreate them on each level init?
Any ideas would be awesome :)


Link to comment
Share on other sites

Hi Guys


I still can't figure this one out. Basically, I have a whole bunch of code sitting in my init: function()


I want to reuse the same code as a basic level/hud setup and I don't want to paste the same code into 20 level files.


Is there any way I can include a snipped inside a .js file or make a reusable code function?


Thanks again :)

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.

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.


  • Recently Browsing   0 members

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