Discuss Scratch

peter-rabbit
Scratcher
15 posts

How do i make a project save.

How do i make my project save using cloud variables.
CATSAREAMAZING-
Scratcher
100+ posts

How do i make a project save.

I'm not sure how to do it with cloud variables. There is a way that you can do it with lists and variables in general. I have a project (unshared) which uses this kind of code. If you want to create a simpler save code (since I'm not the best at explaining intermediate code), I'd recommend checking out this tutorial.
MillionOfficial
Scratcher
500+ posts

How do i make a project save.

Click the Save Now button.
If it doesn't work, open a new tab, put the new tab on scratch.mit.edu, click “peter-rabbit”, then click “Sign out”, then sign in again.
ametrine_
Scratcher
1000+ posts

How do i make a project save.

MillionOfficial wrote:

Click the Save Now button.
If it doesn't work, open a new tab, put the new tab on scratch.mit.edu, click “peter-rabbit”, then click “Sign out”, then sign in again.
i'm assuming they're talking about a cloud-based save system, such as the one in this project
peter-rabbit
Scratcher
15 posts

How do i make a project save.

I want you to give me a way to do a account based saving on the project so even if you close the project you can still load your progress.
dave3m
Scratcher
500+ posts

How do i make a project save.

How you would do this - and whether you can - will depend on how much progress information you need to store and for how many users. It is also worth mentioning that some users will be unable to update Cloud variables in your projects (this would include both New Scratcher accounts and those who are not logged in).

apologies that this gets rather long, but it can be a complicated topic


There are different ways of accomplishing this, both with and without using the Cloud.
  • Some projects use textual “Progress Codes” that the user can ask for to represent their progress.
    You might do this if you don't think that you can store enough data on the Cloud for all of your players. When they load the project again later, they can paste their “Progress Code” back into the game to restore their progress. Some games use passwords as progress codes that tell the game what level you reached.

    The benefit of this approach is that you are not limited in how many players can save their progress. You can also support players who are not logged in or are New Scratchers. The drawback is that it is not automatic and players need to know what to do.
    My two Incursion puzzle projects use progress codes to save player progress, but also use cloud variables to save a list of players who finished the game.
  • Many games will store a leaderboard in Cloud Variables to show what level or score players have achieved.
    This often involves encoding their username along with their score. You might encode their whole name or a shortened version of their name, depending upon how much space you have to work with and how many players you need to support.
    Similarly, when encoding other values you may need to find ways to shorten them to fit enough data for all players, but in a way that loses as little information as possible.
  • As an advanced form of leaderboard, you can match the current user against the data in the leaderboard to figure out where they are in the game when they reload the Project again later. This is very convenient, but may be difficult to do based on the limitations of Cloud Variables.

    The game NODIO by @karkade35 does this and they manage to keep a very large leaderboard by manually integrating the current data from the Cloud into the project using lists that are manually kept up to date. This is great and frees up space in the Cloud Variables for more players, but can be a lot of work.


You can find general information about both Cloud Variable usage and encoding/decoding cloud variables in the Scratch wiki.

There will be “Cloud Engine” projects out there that provide sample block code for accomplishing this, but your project may need to customize them to suit its specific needs. There are some example projects referenced in the Wiki, but I'm not sure how old they are. I use a few different methods in my own projects, but you might find it difficult to find the code within these projects as they are rather large and specific to the data I store for them.




Using Cloud Variables will require you to encode your desired data as digits and then to be able to decode those digits back to their original values. This is often done by converting each character in the original data into a number representing its position in an alphabet that contains all of the needed letters/characters. You can then put all of those numbers together into a string of digits and save them to a Cloud Variable.

Keep in mind that you need to be able to convert it back without getting confused about whether some numbers mean one thing or another. Since you have more than 10 letters to encode, this usually means that you will use two digits to encode each character. i.e., 00 01 02 03 … and so on.

You have a choice when encoding data to have each "field“ or thing be encoded to a known specific length (making it easy to know where to stop reading back digits) or to have ”field“ lengths be a variable number of digits that use a ”delineator" to tell you where to stop: a delineator is a string of digits that you know for sure means that you have reached the end of the current thing you are decoding. This might be a series of one or more zeroes, as long as you don't use the value 00 for anything else.


You will often be converting data from Scratch lists into Cloud Variable digit strings and back again. You might need to combine the data from multiple lists if your game progress consists of multiple factors or items.

For example you might need to store multiple values to represent the progress for each user. The data for each user may then also need to be combined if you are storing it all into one variable. You might also need to use multiple variables to store this information, which you could approach in multiple ways.

peter-rabbit value1 value2 value3 value4 ==> digits encoding the data for peter-rabbit
player2 value1 value2 value3 value4 ==> digits encoding the data for player2
player3 value1 value2 value3 value4 ==> digits encoding the data for player3

===> all joined together to represent the digit strings encoded for all players



Keep in mind the following limits:
  • You have a maximum of 10 Cloud Variables per project.
  • Each Cloud Variable can consist of only numbers (in general the digits 0 - 9 , though a single decimal point is accepted) and is limited to a maximum of 256 digits.
  • You should avoid trying to change the value of Cloud Variables too quickly, or the server might temporarily block your updates. This is easily done by placing a short wait block before any SET command that changes a Cloud Variable.
    wait0.2secsset☁ MyCloudVariableto0124370586901
  • You must avoid trying to set any value containing characters/letters other than digits to your Cloud Variable, or the update will fail and may time you out of further updates temporarily.
  • Only promoted Scratcher accounts may access or update Cloud Variables. You may wish to consider if New Scratchers or people not logged into Scratch may want to play your game.
  • You must not use Cloud Variables to allow users to store freeform text or ‘chat’, as this will be seen as bypassing the safe word filters. You can encode user names for the purpose of identifying whose progress you are recording.

*** Also, be aware that the Cloud server has some ongoing quirks. When you first create a Cloud Variable it may likely not work properly (will appear to reset when you reload your project). To fix this, rename your Cloud Variable after you create it (you can name it back again). It sounds silly, but it generally works.

Last edited by dave3m (Nov. 21, 2024 07:16:05)

kRxZy_kRxZy
Scratcher
1000+ posts

How do i make a project save.

I, think you can do it as I have seen some projects that use this
________________________________________________
Hi, I am a decent coder even though I am obsessed with it. I have been on Scratch for like 7 months and I am enjoying it. I like making games and stories and I like having fame

Last edited by kRxZy_kRxZy (Nov. 21, 2024 07:52:22)

peter-rabbit
Scratcher
15 posts

How do i make a project save.

how do i code this in.
dave3m
Scratcher
500+ posts

How do i make a project save.

We can't tell you exactly how to do this for your project, but you can find examples of code that you could modify for your project. It is certainly possible, but there are limitations that you need to be aware of and work around.


I would start by thinking about:
  • What progress information do you need to store for each user? How many different values and what kind of values are they?
  • How many users do you need to store information for?
  • Can you manage to do this within the limits available (10 variables that can store 2560 digits total, keeping in mind that 100 letters or characters will probably require at least 200 digits to store).
  • You mentioned that you wanted to let users return to the game with their prior progress when loading it again. You will need to be able to both store this information and find it again using the user's name.

  • Have a look at the wiki and my post above to get a better idea of what is involved in converting data from your game to and from Cloud Variables.


Others could help you figure out the scope of a possible solution with more information about that.

If your project needs to store more than a score or a level number for each user, you won't be able to just paste someone else's code into your project. You will need to understand how it works and modify it to suit your specific game values. The code you need for your project will be similar, but must be customized.

You will also need to calculate how much space you will require to store this data for each user. You will use this information when building the code that does the conversion back and forth between your game data and the Cloud variable number strings.
dave3m
Scratcher
500+ posts

How do i make a project save.

To look at it from a very high level, your code may look like this. For simplicity, I will not talk about the differences between encoding fixed-length values and variable-length values (like user names), but you will need to think about that, too.

Preparing to save a Cloud variable

1) Build a digit string that encodes all of the data for one player.
—– Encode the username into digits
—– Encode the first value into digits and add it to the above
—– Encode the second value into digits and add it to the above
—– … and so on

2) Join the digit string for all users together into one (or more) long strings that you can save to Cloud Variables.
You may need to use several Cloud Variables for this if there isn't room

3) Once you have it all prepared, actually save it to the cloud using a Set block (be sure to wait first to avoid trying to write too fast):
wait0.2secsset☁ CloudVariable1toCombinedDigitStrings


Then when reading back your Cloud Variables, you would decode this digit information to restore your game data

1) Preferably, read the data from the Cloud once into a temporary variable instead of referencing it 100s of times. You will iterate over the data in this local variable that has a copy of the data.
setCopyfOfCloudDatato☁ CloudVariable1

2) Read back and decode the data for the First user from the Cloud data
—- Decode the username (and store it)
—- Decode value1 for that user (and store it)
—- Decode value2 for that user (and store it)
—- … and so on until you reach the end of the data for the first user

3) Continue to read back and decode the data for all remaining users found in the cloud data
—- Repeat the above process again for the second user
—- Repeat it again for the third, and so on …
—- You will need to be able to detect when you have no more data or users remaining.

4) To be able to restore a user's progress, you could match their username against the lists you created when restoring data from the Cloud. If their name is found in the list, you can find the associated game progress values that were saved against their name. You could do this while decoding the data, but you would likely do this after (or whenever you needed) by using the decoded list data to find the information.

E.g.,
ifUserListcontainscurrentPlayerName?thensetgameValue1toitemitem#ofcurrentPlayerNameinUserListofGameValue1ListsetgameValue2toitemitem#ofcurrentPlayerNameinUserListofGameValue2ListsetgameValue3toitemitem#ofcurrentPlayerNameinUserListofGameValue3List

This assumes that you record the retrieved game value lists in the same order as a list of retrieved user names.
It would technically be more efficient to look up the player position once and store it in a variable, but Scratch projects tend not to worry about that and they will be small lists so it doesn't really matter.

Last edited by dave3m (Nov. 21, 2024 09:56:49)

alboxer2000
Scratcher
500+ posts

How do i make a project save.

MillionOfficial wrote:

Click the Save Now button.
If it doesn't work, open a new tab, put the new tab on scratch.mit.edu, click “peter-rabbit”, then click “Sign out”, then sign in again.
He's talking about cloud variables, not saving a project in My Stuff.
yay 444th post!

Last edited by alboxer2000 (Nov. 21, 2024 13:29:50)

J_REX2
Scratcher
17 posts

How do i make a project save.

The best way to do this is to use custom extensions on third-party sites such as TurboWarp and PenguinMod, and then upload it there. However, projects with custom extensions can’t be uploaded onto Scratch itself.
If you want to do it without extensions, I’m not really sure tbh.
Breaking_Newsyo
Scratcher
45 posts

How do i make a project save.

Doing something like this is difficult. I recommend you to find a tutorial to do it.

Powered by DjangoBB