Discuss Scratch

P444
Scratcher
500+ posts

Coding and Decoding cloud variables

Guide on how to code and encode (Case Sensitive)


So, here I am, making this guide. I made this guide because lately, a lot of questions on cloud variables have been asked and most are about how to save characters to cloud variables. This is not only for saving characters only for chat rooms, but also saving any character to cloud var. for things like high scores, users visited your project, etc. So let's begin.

Few notes before beginning

Cloud variables are the variables which is the only variable that is stored in the scratch server. It will change (if you coded) and will remain like that without saving. So basically anyone can change the cloud variable if it is on high scores. Since cloud variables can store numbers only this is a guide on how to convert any character to numbers and back to characters from numbers. Also you must be a "Scratcher" in order to use cloud variables.

How to create a simple coding/decoding engine

First of all, begin by creating 5 variables (excluding cloud variable) and a list.
(all characters)//the characters that can be used
(cd)//coded/decoded message
(case)//case detector
(i1)//character recognizer 1
(i2)//character recognizer 2
(c/d :: list)//coded/decoded message (more readable format*)

When you have done that, start as you'd normally start a project.
when green flag clicked//most rcommended method to start
broadcast [message 1 v]
After the broadcast “message 1” you should put when the cloud variable should be changed or decoded. In this example, I am showing you how to code and decode manually by using ask block.
when I receive [message 1 v]
hide list [c/d v]
set [all characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`-=\;',./~!@#$%^&*()_+{}|:"<>? ] //all characters below
wait until <<key [c v] pressed?> or <key [d v] pressed?>
if <key [c v] pressed?> then //c = code and d= decode
code :: custom
else
if <key [d v] pressed?> then
de-code :: custom
end
end
In the above script you can put the characters given here for all characters . . .
Here is what you should do there :
Copy the characters below (without quotes) and paste in the set [all characters] to block:

"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`-=][\;',./~!@#$%^&*()_+{}|:"<>? "
set [all characters v] to [ ]

Case sensing

Thanks for sonicfan12p for suggesting this and for clarifying a doubt on this

First of all, go to your sprite's costumes. If is has any costumes, delete them and/or rename them. Name your first costume “null” without quotes. Next, create a new costume and name it “A” without quotes. Remember you cannot put a same name in 2 cases for 2 costumes in one sprite. So create a new costume and name it “at”. Remember to put a letter after a and it should be same for all the next costumes and all letters in this costume should be simple letters. Now carry on with making new costumes and naming them same way. The next 3 costumes will be “B”,“bt”,“C” and so on. You can find more in here. After you complete up to Z, you'd have exactly 53 costumes, if not check again if you have done it in order.
An example of what it should look like

Now when you have done that, make a custom block called Detect case of letter (character) and put these codes on.
define Detect case of letter [character]
if <(length of (character)) > [1]> then
set [case v] to [error!] //indicates that more than one character was entered
stop [this script v]
end
switch costume to [null v] //it should be your very first costume
switch costume to (character) //if the character is lowercase, it will stay on "null"
if <(costume #) = (1)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character) [t]) //all lowercase costumes end in "t" or your lettered choice (refer to pattern above)
end
if <(costume #) = (1)> then //if the sprite still has not changed costume
set [case v] to [other] //indicates that a non-alphabetic character was used
stop [this script v]
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning it is a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
With that, you have completed the case detecting part

Coding and Decoding

Moving on, here is the way to code (simplest method):
define code
ask [Type what you would like to code] and wait//as I said, I am using an example that uses ask block
set [i1 v] to [0]
set [i2 v] to [0]
set [cd v] to []//absolutely nothing should be written inside box
repeat (length of (answer))//changes all letters of answer
change [i2 v] by (1)//changes the letter of answer being coded
Detect case of the letter(letter (i2) of (answer))::custom //block we made earlier

if <(case) = [upper]> then
set [i1 v] to [0]//capital letters
else
set [i1 v] to [27]//simple letters and other symbols
end

repeat until <(letter (i1) of (all characters)) = (letter (i2) of (answer))> //repeats until find the letter

change [i1 v] by (1)
if<(letter (i1) of (all characters)) = (letter (i2) of (answer))> then//checks all characters for the specific letter in answer
if <(i1) < [10]> then

set [cd v] to (join (cd) (join [0] (i1))) //makes sure the coded letter is 2 digits
else
set [cd v] to (join (cd) (i1))
end

end


end
if <(i) = [27]> then
set [cd v] to (join (cd) (i1))
end
end
delete (all v) of [c/d v]
add (cd) to [c/d v]//makes it easier to read and copieable
after this you can put a
wait until <key [space v] pressed?>
broadcast [message 1 v]
to resume coding or decoding as needed

How does it work?
Firstly, you have put all the characters inputable to your all characters variable. The script above finds the letter of your answer (in this case) and finds that letter of the answer in the all characters. Than what it does is simply take the number of letter of all characters that matched the letter of your answer and than put it to the variable cd. Also, it is in 2 digit form. So if the i1 is smaller than 10, it makes sure that a 0 is joined before the i1 to make it 2 digits.

Before continuing. . .
If you have done exactly ask mentioned above, save your project and try to to start it in turbo mode. Press “c” and type in “Hello” without quotes. If you have done it right, you'd get “0831383841” this as an answer. If else, try to go back and try to find the mistake.

Now, how will you change it back to readable format? Don't worry, I'll tell you

Remember that de-code block that you put earlier in project that activates when d pressed? Do this for it.
define de-code
delete (all v) of [c/d v]
ask [Type in the code to decode] and wait
set [i1 v] to [0]
set [cd v] to []//absolutely nothing in the box, not even space
add [] to [c/d v] //absolutely nothing in the box, not even space
repeat ((length of (answer)) / (2))//since the characters are coded into 2 digit form
set [cd v] to []//nothing in box
set [i2 v] to [0]
repeat (2)//2 digit de-code formula
change [i1 v] by (1)
set [cd v] to (join (cd) (letter (i1) of (answer)))

end
set [i2 v] to (cd) // remembers the length of cd

set [cd v] to (letter (i2) of (all characters))//back to readable text
replace item (1 v) of [ c/d v] with (join (item (1 v) of [c/d v]) (cd))
end
show list [c/d v]
as said before after this you can put a
wait until < key [space v] pressed?>
broadcast [message 1 v]
to resume coding or decoding as needed

How does it work?

Simple. It is just the opposite way that you coded the characters. It searches for the 2 digit number in the answer and than finds and put the character on that number of all characters to readable format.

Complete :D

Here is a project that you'd see if you have done correctly:
Link - http://scratch.mit.edu/projects/50885752/

You have now completed the coding and decoding process. Now go ahead and save it and test it.Press green flag shift to run turbo and press “d”. Use this “0831383841” and decode it. It should say “Hello” else go try finding out your mistake, or question below here. I'd do my best to answer

This shows only coding and decoding, so now you can use the code and decode scripts to put high scores and things. Also, all the scripts shown here are tested and by me and are working. If you have anything to ask, feel free to ask and have a nice day!

Last edited by P444 (Sept. 9, 2016 08:57:27)


Hey there random person scrolling through one of my posts! Hope you have a nice day (ノ◕ヮ◕)ノ*:・゚✧


Reserved for advertisements >:3

sonicfan12p
Scratcher
1000+ posts

Coding and Decoding cloud variables

This is pretty close to what I use, with a couple of minor changes. (plus mine is case sensitive, if you're interested in adding that feature) If there's a more efficient method of doing it than what you said, I've never seen it.

Inactive account. Please direct all questions to my secretary.
P444
Scratcher
500+ posts

Coding and Decoding cloud variables

sonicfan12p wrote:

This is pretty close to what I use, with a couple of minor changes. (plus mine is case sensitive, if you're interested in adding that feature) If there's a more efficient method of doing it than what you said, I've never seen it.
Thanks, added it

Hey there random person scrolling through one of my posts! Hope you have a nice day (ノ◕ヮ◕)ノ*:・゚✧


Reserved for advertisements >:3

sonicfan12p
Scratcher
1000+ posts

Coding and Decoding cloud variables

No problem.

Inactive account. Please direct all questions to my secretary.
qwertysamo
Scratcher
13 posts

Coding and Decoding cloud variables

Great! _meow_

Check out my chat - made safe by a dictionary built by the Moderators!
https://scratch.mit.edu/projects/77622766/
triforcefox
Scratcher
83 posts

Coding and Decoding cloud variables

Testing it out right now I have done simple decoding/encoding but have never SUCCESSFULLY made a cloud version.


VectorHero
Scratcher
88 posts

Coding and Decoding cloud variables

Hey!! there is no “repeat until” block in scratch editor 2.0 (it is in scratch 1.0), So can we use “repeat” block?


Browser : Chrome Version 42.0.2311.90 m System OS : Windows Flash: Adobe Flash 17.0 (release 0)
deck26
Scratcher
1000+ posts

Coding and Decoding cloud variables

VectorHero wrote:

Hey!! there is no “repeat until” block in scratch editor 2.0 (it is in scratch 1.0), So can we use “repeat” block?
Oh yes there is - look between ‘wait until’ and ‘stop all’ in the Control tab.
Wishey2002
Scratcher
1 post

Coding and Decoding cloud variables

                                         :cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool::cool:::D:D:D:D:D:D:D:D:D
when green flag clicked
move (111111) steps
play sound [UP TOWN FUNK BABE!!! XD v] until done
wait (1) secs
set pen color to [#ff0088]
wait (12334) secs
kieranblackley
Scratcher
500+ posts

Coding and Decoding cloud variables

Very good i will try this right now

Bored? Want to see something great? Check out my profile today!
mrbobbygreathead
Scratcher
1000+ posts

Coding and Decoding cloud variables

The case sensitivity bit is great so I will add it to my skills!

We need you to tell the scratch team we want nested lists! (Also known as first class lists, multidimensional lists or just lists inside lists). Support now!
Please try out SSMS, the radical new approach to Scratch music! Compose, share and use music all inside scratch!
mrbobbygreathead
Scratcher
1000+ posts

Coding and Decoding cloud variables

sonicfan12p wrote:

This is pretty close to what I use, with a couple of minor changes. (plus mine is case sensitive, if you're interested in adding that feature) If there's a more efficient method of doing it than what you said, I've never seen it.
There is, but it also involves costumes so it would need 2 sprites…

We need you to tell the scratch team we want nested lists! (Also known as first class lists, multidimensional lists or just lists inside lists). Support now!
Please try out SSMS, the radical new approach to Scratch music! Compose, share and use music all inside scratch!
SkullduggeryPleasant
Scratcher
2 posts

Coding and Decoding cloud variables

Ummm, is there a limit to how many cloud variables there can be?
jokebookservice1
Scratcher
1000+ posts

Coding and Decoding cloud variables

SkullduggeryPleasant wrote:

Ummm, is there a limit to how many cloud variables there can be?
Sorta, Scratch prevents you from making a new one at 10, but there is a bug (that should rarely be used because is going against the Scratch Team's decision) where you can create multiple cloud variables at the same time, and thus avoiding the limit.
It is because Scratch records if a cloud variable is created,after the OK button is clicked, but prevents you from making a new one before you tick the Cloud Variable checkbox. This inconcistency allows you to create more than 10.
On a seperate note..
Why do you need the lowercase lettered costumes, surely a lowercase letter ill stay at costume null whether the costume letter+t exists? It seems like it is taking up 2x space needed? (correct me if wrong)

Last edited by jokebookservice1 (April 9, 2016 22:07:37)

cm8263
Scratcher
100+ posts

Coding and Decoding cloud variables

SkullduggeryPleasant wrote:

Ummm, is there a limit to how many cloud variables there can be?

Yes, 10 per project.

And PLEASE check before you post, because you might just be Necro-Posting!

If I helped you please look @ my profile, you may just like what you see…
forever

if <(Your Skill) < (My Skill)> then
say [Did I use it to help you?]
end
P444
Scratcher
500+ posts

Coding and Decoding cloud variables

jokebookservice1 wrote:

-snip-
On a seperate note..
Why do you need the lowercase lettered costumes, surely a lowercase letter ill stay at costume null whether the costume letter+t exists? It seems like it is taking up 2x space needed? (correct me if wrong)
The first costume which is null is used to identify all non alphabetic characters and any character which might not be in the original character list. So it would be easier to tell what happened if anything goes wrong and where it is. That will actually work. I just copied that part from the wiki and didn't bother doing anything else on that part… I would need to do some testing on that method and will update if necessary. Thank you for the idea!


cm8263 wrote:

SkullduggeryPleasant wrote:

Ummm, is there a limit to how many cloud variables there can be?

Yes, 10 per project.

And PLEASE check before you post, because you might just be Necro-Posting!
Well, I don't think it can be called necro posting as the thread still seems to be useful.

Hey there random person scrolling through one of my posts! Hope you have a nice day (ノ◕ヮ◕)ノ*:・゚✧


Reserved for advertisements >:3

mineawesomeman
Scratcher
12 posts

Coding and Decoding cloud variables

I just coded using your coder, and I tested it by putting in “Hello” though when I tried it, it just stayed there. I'm in turbo mode and it still doesn't work. DO you know why?
jokebookservice1
Scratcher
1000+ posts

Coding and Decoding cloud variables

mineawesomeman wrote:

I just coded using your coder, and I tested it by putting in “Hello” though when I tried it, it just stayed there. I'm in turbo mode and it still doesn't work. DO you know why?
We can't help unless you give us more info. Please share the project and provide a link for the best help
mineawesomeman
Scratcher
12 posts

Coding and Decoding cloud variables

Ok, here is the project with all the code forum this post, though I don't want to spoil anything to only look at stuff on top of the comment https://scratch.mit.edu/projects/110311316/

Last edited by mineawesomeman (May 19, 2016 01:08:43)

jokebookservice1
Scratcher
1000+ posts

Coding and Decoding cloud variables

mineawesomeman wrote:

Ok, here is the project with all the code forum this post, though I don't want to spoil anything to only look at stuff on top of the comment https://scratch.mit.edu/projects/110311316/
You covered the whole script, and the problem was with a script underneath the comment. You need to connect the green flag script to the green flag hat, it is currently disconected and so the variable that stores all the chars never gets set

Powered by DjangoBB

Standard | Mobile