Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Construct 2

You're reading from   Learning Construct 2 Design and create your own engaging, extensible, and addictive game using Construct 2

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781784397678
Length 234 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Aryadi Subagio Aryadi Subagio
Author Profile Icon Aryadi Subagio
Aryadi Subagio
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

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

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image