Book Image

Learning Construct 2

By : Aryadi Subagio
Book Image

Learning Construct 2

By: Aryadi Subagio

Overview of this book

Table of Contents (17 chapters)
Learning Construct 2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Storing data in the player's machine


We know how to store data in an array and dictionary and how to show them onscreen, great! However, there's one thing to keep in mind when working with arrays and dictionaries: they will lose their values when the game is closed. The players might close the web browser window. Whenever they do this, they close the game, and the game will not remember the last value you put inside the array or the dictionary.

In most cases, this is not what we want. If we want to keep a score and then compare it to create a leaderboard, we want the game to remember it even after the game is closed. To do this, we need to store the data in the player's computer. So, when we start the game next time, our game can still remember the player's score. How do we do this? Using a WebStorage object.

Note

A WebStorage object does not store data in an online storage despite the name. It stores data on the player's computer locally. It also works when used to create offline games with...