Discuss Scratch

Backbranch
Scratcher
6 posts

How do I assign a cloud variable to a username to make indevidual saves?

I made a simple tycoon game and was wondering how I could assign the cloud variables to a username to create a automatic individual save system. The desired effect would be for one person to log in and have a certain save state, (score, coinlevel, etc.) but if another person were to log in they would have a different save state. I would also need to make sure that a new user would start out with nothing. How would I do this?

Game:https://scratch.mit.edu/projects/664135798/

Thanks!
-Backbranch

NMario84
Scratcher
1000+ posts

How do I assign a cloud variable to a username to make indevidual saves?

You need to encode, and decode all that data. Otherwise I would just assume to use a save code system for that sort of thing.

https://en.scratch-wiki.info/wiki/Encoding_and_Decoding_Cloud_Data
Backbranch
Scratcher
6 posts

How do I assign a cloud variable to a username to make indevidual saves?

What would I do with the encoded data? Do you have to tie it to the cloud variables somehow?
helloworldbyeworld
Scratcher
1000+ posts

How do I assign a cloud variable to a username to make indevidual saves?

Backbranch wrote:

What would I do with the encoded data? Do you have to tie it to the cloud variables somehow?
Once you have the encoded data, simply set the cloud variable to it.

But if you mean a cloud saving system, you will have to encode the entire data. You want to make a username-data paring like this:

someuser:someuser's game data
anotherusername:anotherusername's game data
helloworldbyeworld:helloworldbyeworld's game data
...

Since you are going to encode a string to numbers for storage in a cloud variable, you will need to turn those parings into a string. Do this by separating each paring with a delimiter, like ‘,’. So the parings will become something like this:

someuser:gamedata,anotherusername:gamedata,helloworldbyeworld:gamedata,...,...

Then you can encode that string.
HirGar1945
Scratcher
5 posts

How do I assign a cloud variable to a username to make indevidual saves?

Do keep in mind that the Scratch Cloud variables have a character limit of 256. So I think maybe you could add something to counter an overflow, or find a way to have it work with multiple variables.

Powered by DjangoBB