Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Save and Load Project Data

Save and Load Project Data

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 929 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

    When we save a project, all the data stored in the variables/lists/tables are saved as well. However, when users run projects they don’t own, they can not save data this way.

    For example, suppose you have published a game project, and you want other users to be able to save their “progress”, so that they can resume the game in the future.

    One solution is to use “project data”, which allows the program to save the data of any user as part of the project.

     
     

    Save Project Data

    To save some data as part of a project, you can use the following block:

    e79dd4c8-f4b3-4969-b465-a1704adfe348-image.png

     
    It takes 3 inputs:

    • scope: If this data is “public”, then all users can read this data when they run this project. If this data is “private”, then other users won’t be able to read this data, so it is private to the user who saves this data under his/her user ID. This block will not do anything if the user has not logged in, since it needs to know the user’s ID to decide how to save this data.
    • data: the actual data to be saved, which can be any text.
    • name: the name of this data, which is needed to read this data out later.

     
    For example, if your game has many levels, and you want to save each user’s current level (stored in the variable “my level”), you can save it as a “private” data for each user:

    39c50871-1c85-4e72-9120-7797deb0e982-image.png

     
     

    Load Project Data

    After the data has been saved as part of the project, you can use the following block to read it out at any time:

    b1a0d9e6-982d-4844-8b0b-280d8c0ef753-image.png

     
    You need to specify the name associated with that data to read it out.

    Each user has permission to read out any data that is saved by that user, either it is public or private. However, if the data was saved as “private”, then only that user can read it later.

    For example, suppose user A has saved 2 pieces of data: a public data named “p1”, and a private data named “p2”.

    Later, user A can load both data items out using the names “p1” and “p2”. However, for another user B, he or she can only read the data named “p1”.

     
     

    List All Data Names

    Suppose you save each user’s game score using the “user name” block (from the sensing category) as the name, and you would like to list all the scores of all users. You can use the following block to get the list of all names:

    013f607b-ed59-46a4-b398-0ec8b7ff65c6-image.png

     
    The result will be a long text separated by “&&”, like “x&&y”. This is assuming the data names do not contain “&&” themselves, so you can easily split the data names into a list using the following block:

    432457c0-fd2f-471a-8a2e-385671dd2fcf-image.png

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode