-1

Currently, I am making a game and when you die, it brings you to the gameover screen which is a separate html file. Underneath the words gameover, I want it to show the players score. The problem is that the score that the player gets is in the first html file. How would I send that score to the other file?

OneStig
  • 868
  • 2
  • 11
  • 24
  • 1
    I don't understand why you are using an other html file to display just a game over. You can make a div for example , hide it by default and show it when the game is over – AshBringer Jun 24 '15 at 17:55
  • 1
    It depends on you underlying technology...if you are using `java` or `.net` or `php` or pure `html/javascript`... – brso05 Jun 24 '15 at 17:56
  • @StigCoder04 you can always use a cookie... – brso05 Jun 24 '15 at 17:58

2 Answers2

2

Try using GET variables:

Access GET directly from JavaScript?

This is an easy way to give data to a page from another. You have probably seen its use and haven't noticed it.

The GET variables are passed through the URL, and can be accessed by that page for processing.

Example URL w/ GET variables:

"index.html?score=50&player=joe"

This would pass the score and player variables with the values '50' and 'joe', respectively.

To setup these variables, you just have to append them, as in the example.

The link above is to how to access those variables via javaScript, which would probably be fine for your purposes.

More literature on GET: http://html.net/tutorials/php/lesson10.php

Community
  • 1
  • 1
Snappawapa
  • 1,697
  • 3
  • 20
  • 42
2

Assuming the score is saved in javascript, which is most likely, you could just put all your javascript into a .js file and then have your html files use that .js file. For example, you could put all your code in game.js, define the score variable there, and then have both seperate html files use game.js with <script src="game.js"></script>.

Then variables will be usable on both files as both files use the same javascript file.

uniqueusername
  • 440
  • 1
  • 5
  • 9