Discuss Scratch

JGames101
Scratcher
100+ posts

LocalStorage Variables Extension

What Does it Do?
My LocalStorage Extension adds two new blocks:
[highscore] :: reporter extension
set [highscore] to [12] :: extension
These act just like the variables in Scratch, but they have one big difference: Unlike Scratch variables, they don't go away when the page is closed or reloaded. They stay as long as the player and the creator want.

This is really good in cases where you want to save user data. Usually, you would do that with Cloud Data. But that's slow and inefficient, especially when you have a lot of players. LocalStorage is useful in that case, because you can store everything you want to on the player's device.


I've Seen This Before.
There is another localStorage Extension, but it only allows you to use one variable. This one allows you to create as many as you would like.


Try it Out
Try it in ScratchX

Code
new (function() {
	var ext = this;
	var descriptor = {
		blocks: [
			['r', '%s', 'readLocalStorage', 'highscore'],
			[' ', 'set %s to %s', 'setLocalStorage', 'highscore', '12'],
		],
		url : 'https://jgames101.github.io/scratch-extensions/localstorage.html'
	};
	ext._shutdown = function() {
		
	};
	
	ext._getStatus = function() {
    if (window.localStorage) {
		  return {status:2, msg:'LocalStorage supported by your browser!'};
    } else {
      return {status:0, msg:'LocalStorage is not supported by your browser. Try recent versions of Chrome or Firefox.'};
    };
	};
  
	ext.readLocalStorage = function(name) {
		return localStorage.getItem(name);
	};
	
	ext.setLocalStorage = function(name, value) {
		return localStorage.setItem(name, value);
	};
	ScratchExtensions.register('LocalStorage Variables', descriptor, ext);
})();
Thank you!
If you like this extension, check out my previous one, Desktop Notifications.

Last edited by JGames101 (Nov. 13, 2017 07:08:49)



Hey! I like working with Scratch 3.

Scratch 3 Modding

My Website
savaka
Scratcher
1000+ posts

LocalStorage Variables Extension

JGames101 wrote:

Try it in Scratch 3
do you mean ScratchX?


Signature protected by Savaka Antikumquat
JGames101
Scratcher
100+ posts

LocalStorage Variables Extension

savaka wrote:

JGames101 wrote:

Try it in Scratch 3
do you mean ScratchX?
Woops yes thank you xD


Hey! I like working with Scratch 3.

Scratch 3 Modding

My Website
GamesFactory_
Scratcher
9 posts

LocalStorage Variables Extension

Does it support letters?
JGames101
Scratcher
100+ posts

LocalStorage Variables Extension

GamesFactory_ wrote:

Does it support letters?
Yes, it does


Hey! I like working with Scratch 3.

Scratch 3 Modding

My Website
Blue_Science
Scratcher
100+ posts

LocalStorage Variables Extension

Does this works with cookies or is it anything else ?


┌──────────────────────────────────────────────────────┐
│ Want more ? ☛ My accountLastest projectBest projectAll games:D │
└──────────────────────────────────────────────────────┘

Powered by DjangoBB

Standard | Mobile