Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Save and Load Project Data

    2D Blocks
    1
    1
    255
    Loading More Posts
    • 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.
    • info-creaticode
      CreatiCode last edited by admin

      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 Reply Quote 0
      • First post
        Last post