Jump to content

Restart state but keep saved variable?


Recommended Posts

I'm doing a round based game. So after you've killed so many enemies it'll pop up, "Round 1", after some more, "Round 2" and so on. The amount of enemies doesn't change it's just the round that increases after you've killed say 20 enemies.


I have a current variable at the top of my game.js file

var currRound = 1;
var EnemiesKilled = 0;

Every time I kill an enemy I increment up the variable then in one of the collision handlers I do if EnemiesKilled == 20 then show some text

newLevel.setText("Woo!! Round " + currRound + "!");

and restart the round via

setTimeout(function() {
}, 1000);

The thing is, it whipes the variable of EnemiesKilled. How can I keep that variable so I always know how many enemies the player has killed?

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