Jump to content

Global Variables - Full Screen Mobile Template


RubyHelix
 Share

Recommended Posts

I've been using this forum as a valuable tool along with all the wonderful examples provided to us.  I finally have my first simple HTML5 game nearly complete but i'm having an issue with accessing the global variables in the Full Screen Mobile Template.

 

I'll post the code I'm talking about below:

 

 

Boot.js

BasicGame = {    // GLOBAL VARIABLES    score: 0,    // MUSIC THAT PLAYS BETWEEN STATES    music: null,   // CHECK AGAINST DEVICE ORIENTATION TO DETERMINE BEHAVIOR OF GAME    orientated: false	};BasicGame.Boot = function (game) {};BasicGame.Boot.prototype = {    preload: function () {    },

Now, first I had noticed that in this template variables don't look like how I would normally declare a variable:

var score = 0;

In my loop timer I basically have the timer increment the score:

 

Game.js

updateCounter: function() {			score++;		scoreText.setText("Score: " + score);			}

If I use the above code without first declaring the score variable in this state then I get a variable undeclared error. 

 

My concept is that I want to add the score to the MainMenu state but when attempting to do so it states the variable is not declared.

 

How would I access the global variable from another game state when declaring it as has been done in this template?

 

 

Thanks for any help you can provide!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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