ZEP Guidebook (EN)
  • Hello ZEP Script
  • ZEP Script
    • 💻ZEP Script Guide
      • ZEP Script Development Guide
        • JavaScript Development Tips
        • ZEP Script Deployment Guide
        • TypeScript Development Tips
      • Explore ZEP Script
        • Tutorials
          • Displaying a Message
          • Changing Avatar Image
          • Using HTML
          • Communicating with an External API
          • Creating a 2-Second Stun Effect
        • ZEP Script Example Code
          • Timer
          • Zombie Game
          • Paintman Game
          • Hangul Quiz Game
          • Avoid Poop Game
          • Boxing Game
          • Sidebar App
          • Race
      • ZEP Script FAQ
      • Appendix
        • ZEP Script Use Cases
        • Understanding Spaces and Maps
        • JavaScript Keycode List
        • Understanding Sprite Sheets
        • TileEffectType Detailed Explanation
        • What are Reference Coordinates?
        • Communicating with an External API
        • How to Use URL Query Strings
        • How to Change the Mobile Interaction Button
        • Grammar Available for Widgets
        • Object Interaction with ZEP Script
        • Object npcProperty
    • 📘ZEP Script API
      • API Summary
      • ScriptApp
        • Lifecycle
        • Field
        • Storage
        • Event Listeners
        • Callbacks
        • Methods
      • ScriptMap
        • Field
        • Methods
      • ScriptPlayer
        • Field
        • Methods
      • ScriptWidget
        • Field
        • Event Listeners
        • Methods
  • Others
    • Homepage
    • FAQ
    • Twitter
    • Discord
Powered by GitBook
On this page
  • How to Store Data in App Storage
  • How to Read the App Storage Value
  • App Storage Example

Was this helpful?

  1. ZEP Script
  2. ZEP Script API
  3. ScriptApp

Storage

App storage is where you keep the app data inside Spaces.

How to Store Data in App Storage

Recommended

App.setStorage(string);

The App.setStorage function is a data storage function complementing existing app data storage methods.

Not recommended

App.storage = string; App.save();

If the app is running on several maps in the same Space, the above method may cause issues such as data being overwritten.

How to Read the App Storage Value

App.getStorage(function(){})

The App.getStorage function helps synchronize the app data so that it can have the same data by checking if the same app is running on another map within the same Space.

As the App.getStorage function is an asynchronous function, synchronization cannot be guaranteed if you add a code that uses App.storage on the very next line of this function.

App Storage Example

Install the example code below as a sidebar app and press Q on another map in the same Space to see if the "count" value is synchronized.


App.onStart.Add(function(){
	if(App.storage == null){
		App.setStorage(JSON.stringify({count: 0}))
	}
})
// // Activates function when q is pressed
App.addOnKeyDown(81,function(player){
	// Updates App.storage and executes a callback function
	App.getStorage(function () {
		let appStorage = JSON.parse(App.storage);
		appStorage.count += 1;
		App.sayToAll(`count: ${appStorage.count}`)
		// Uses App.setStorage to save any changes
		App.setStorage(JSON.stringify(appStorage));
	});
	// Synchronization not guaranteed if you add a code that uses App.storage on the very next line of the App.getStorage function.
	App.sayToAll(App.storage);
})
PreviousFieldNextEvent Listeners

Last updated 2 years ago

Was this helpful?

📘