Jump to content

Global Variable for Game Difficulty Question


Heppell08
 Share

Recommended Posts

If i have in my main menu a button, that button begins the game state, the game then begins without issue. My issue is that i want to change a number externally from game. 

Mainly the difficulty selection.

This is the only part of my code im battling with and i've scoured the net for examples and answers but cant seem to find a straight forward answer. I've looked in phaser for help but still not finding an answer.

Basically i want to OOP code a global variable, a number. I press button in one state 'Menu' then when game state starts the number i selected 'Difficulty' is changed in the game state to accommodate my needs.

Maybe i'm doing this wrong i have no idea at all. Maybe i need to make something a bit more complex, a bit more simple i have no idea.

 

Link to comment
Share on other sites

Ok i figured it out. I placed the difficulty and the number in the button function like so:

startGame: function (pointer) 	{		console.log('lets play');		this.game.difficulty = 10;		this.game.state.start('Game');			}

then declared the variable of difficulty in my game without referencing a number or string to it. Simply put it, i did this:

 

var difficulty;

 

 

 

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...