Sign in to follow this  

Global Variables - Full Screen Mobile Template

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:




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:



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!

Share this post

Link to post
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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.