Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to use cloud
- Rickyickerson
-
Scratcher
80 posts
How to use cloud
I want to make a game that could be a lot better with could. The problem is, I haven't a clue how it works.
- kieranblackley
-
Scratcher
500+ posts
How to use cloud
Cloud is basically a variable that is sent globally. For exmple someone set the cloud variable to 108 in a project. People viewing the project at the same time will see the variable change to 108 as well.
Cloud variables only support numbers and no letters. For example it cannot support:
“apple123” (Letters are in this string. Even though there are numbers in it, it cannot support this string.)
but it can support:
“984” (No letters are in this string. Only numbers.)
To make cloud variables support strings you need to encode data. You can find more about encoding data on scratch.
The person who looks at the cloud variable cannot read just numbers though so the data has to be decoded. You can find more about decoding data as well on scratch.
Hopefully this post introduces you to Cloud.
Cloud variables only support numbers and no letters. For example it cannot support:
“apple123” (Letters are in this string. Even though there are numbers in it, it cannot support this string.)
but it can support:
“984” (No letters are in this string. Only numbers.)
To make cloud variables support strings you need to encode data. You can find more about encoding data on scratch.
The person who looks at the cloud variable cannot read just numbers though so the data has to be decoded. You can find more about decoding data as well on scratch.
Hopefully this post introduces you to Cloud.
- Rickyickerson
-
Scratcher
80 posts
How to use cloud
Does that mean the game needs to pick a random number and that is like a save password?
- kieranblackley
-
Scratcher
500+ posts
How to use cloud
Does that mean the game needs to pick a random number and that is like a save password?It won't pick a random number and make that a save code as that would be complex to make where a random number such 984 means that I am in level 10 in a game whilst 985 means I am at level 9. The best way to make save codes is to use a saving engine which is very easy to make. Here is an article that details such things.
Last edited by kieranblackley (Oct. 28, 2018 10:22:13)
- kieranblackley
-
Scratcher
500+ posts
How to use cloud
Encoding is simple. All that is needed is this script:
define Encode (string)
set [i v] to [0]
set [abc v] to [abcdefghijklmnopqrstuvwxyz01234567890!@£$%^&*()_+{}:"|<>?~±§`,./;'\-=]
set [Encoded Data v] to []
repeat (length of (string))
change [i v] by (1)
set [i2 v] to [0]
repeat until <<(letter (i2) of (abc)) = (letter (i) of (string))> or <(i2) > (length of (abc))>>
change [i2 v] by (1)
end
if <(i2) < [10]> then
set [i2 v] to (join [0] (i2))
end
set [Encoded Data v] to (join (Encoded Data) (i2))
end
- kieranblackley
-
Scratcher
500+ posts
How to use cloud
Decoding is also simple to make as well. Here is the decoding script:
define Decode (data)
set [i v] to [1]
set [Decoded Data v] to []
set [abc v] to [abcdefghijklmnopqrstuvwxyz01234567890!@£$%^&*()_+{}:"|<>?~±§`,./;'-=]
repeat ((length of (data)) / (2))
set [Decoded Data v] to (join (Decoded Data) (letter (join (letter (i) of (data)) (letter ((i) + (1)) of (data))) of (abc)))
change [i v] by (2)
end
- deck26
-
Scratcher
1000+ posts
How to use cloud
The problem with trying to use the cloud for save codes is that you'd need to encode the username to know who the code belongs to. At 2 digits per letter most usernames will need around 30 digits to store. Each cloud var can only hold 128 digits and you only have 10 per project so you can quickly see that you'll only be able to hold data for a limited number of users. May be enough for your purpose but important to know the limits.
- Discussion Forums
- » Help with Scripts
-
» How to use cloud