Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Encode/Decode
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
So I have made the Encoder block, however the decoding is what I am a bit stuck on.
so I have ‘0’ as ‘00’ and 1 as ‘01’ ect, you get the idea. But now when goto decode, how would I go about reading both digits as 1?
I am going to use this for safe chat, and I am considering registering every word in the oxford dictionary.
Another problem I have is detecting each word that is entered, for when I use safe-chat.
The reason I am using safe-chat is due to Scratch rules.
Safe-chat is quite stressful to setup however and I am curious about something, if I setup a disclaimer at the start of the project before people play it, and the disclaimer says something like:
'Use chat, at your own risk. I (BowWhalley) am not responsible for any violence, or in inappropriate language seen when using chat.
Do Not post any information about yourself in real life, to the chat.
Do Not use violent or inappropriate language.
Do Not break the scratch rules when in chat.
Be respectful.'
Would that allow me to not use safe-chat? (Hoping for moderator/staff of Scratch site, to answer that last question
)
so I have ‘0’ as ‘00’ and 1 as ‘01’ ect, you get the idea. But now when goto decode, how would I go about reading both digits as 1?
I am going to use this for safe chat, and I am considering registering every word in the oxford dictionary.
Another problem I have is detecting each word that is entered, for when I use safe-chat.
The reason I am using safe-chat is due to Scratch rules.
Safe-chat is quite stressful to setup however and I am curious about something, if I setup a disclaimer at the start of the project before people play it, and the disclaimer says something like:
'Use chat, at your own risk. I (BowWhalley) am not responsible for any violence, or in inappropriate language seen when using chat.
Do Not post any information about yourself in real life, to the chat.
Do Not use violent or inappropriate language.
Do Not break the scratch rules when in chat.
Be respectful.'
Would that allow me to not use safe-chat? (Hoping for moderator/staff of Scratch site, to answer that last question
)Last edited by BowWhalley (Oct. 28, 2015 07:26:48)
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
That wasn't very helpful
. If you want to remove your reply, I believe there is an option to delete it. I assume you are re-typing it though
.
. If you want to remove your reply, I believe there is an option to delete it. I assume you are re-typing it though
.Last edited by BowWhalley (Oct. 28, 2015 07:52:50)
- drmcw
-
Scratcher
1000+ posts
Encode/Decode
If you have a variable with a string “01” and want to convert it to a number then you need to use a block that expects a number e.g
You can't add disclaimers. A project will still be reported and removed if it contains anything inappropriate.
set [number v] to ((numeric string) + (0))
You can't add disclaimers. A project will still be reported and removed if it contains anything inappropriate.
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
If you have a variable with a string “01” and want to convert it to a number then you need to use a block that expects a number e.gset [number v] to ((numeric string) + (0))
You can't add disclaimers. A project will still be reported and removed if it contains anything inappropriate.
1. That doesnt seem to make much sense to me.
2. It would not be the project containing inappropiate material, it would be the user playing/using it.
- drmcw
-
Scratcher
1000+ posts
Encode/Decode
1. In the script If numeric string contains “1” or “01” or “000000001” then afterwards number will contain 1.
2. Doesn't matter will still be banned.
2. Doesn't matter will still be banned.
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
1. In the script If numeric string contains “1” or “01” or “000000001” then afterwards number will contain 1.That is still beyond me.
2. Doesn't matter will still be banned.
I created a variable called
(doubledigitrecorder), I want it to record 2 digits then decode those 2 and add it to the decode answer, I tried it a few times and it didn't work. The reason I am doing this is because if I dont, it records ‘1’,'8' seperetly instead of ‘18’.
Here is the code i use to encode and decode, encoding is successful, decoding is not.
The list ‘characters’ lists 0-9,a-z and spacebar.
The list ‘numbers’ lists 00-37'


Last edited by BowWhalley (Oct. 28, 2015 10:52:23)
- drmcw
-
Scratcher
1000+ posts
Encode/Decode
You need to loop in steps of 2 to decode, so to get the index to the characters
repeat ((length of (encoded string)) / (2))
set [index to characters v] to (join (letter (input scanner) of (encoded string)) (letter ((input scanner) + (1)) of (encoded string)))
...
change [input scanner v] by (2)
end
- deck26
-
Scratcher
1000+ posts
Encode/Decode
Personally I wouldn't encode and decode text from a fixed list. If the length of your source word list is less than 10000 you can represent each word by 4 digits which gives the item number for the word in the list. Only one and two letter words will require so few digits if you use encoding and decoding which involves much more work.
We'd have to see your project to get the context - what are the contents of Numbers and Characters for example?
Re having to have a white list. You're responsible for what your project displays. Only your project can read the cloud data belonging to it but since that is purely numeric it can't be offensive - but can become so when your project decodes it and that is your responsibility.
We'd have to see your project to get the context - what are the contents of Numbers and Characters for example?
Re having to have a white list. You're responsible for what your project displays. Only your project can read the cloud data belonging to it but since that is purely numeric it can't be offensive - but can become so when your project decodes it and that is your responsibility.
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
https://scratch.mit.edu/projects/85351970/ and I am aware of encoding words instead, I am concidering doing that, I can easily change the characters to words if need be.
- deck26
-
Scratcher
1000+ posts
Encode/Decode
As @drmcw says you need to be looking at two digits at a time. How can ‘letter’ of a variable ever equal a two-character string which is what you're trying to do in your decode script?
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
As @drmcw says you need to be looking at two digits at a time. How can ‘letter’ of a variable ever equal a two-character string which is what you're trying to do in your decode script?I know. I tried doing this a few times and failed. I need someone to help me with this.
- deck26
-
Scratcher
1000+ posts
Encode/Decode
When you encode you're saving two digits to represent a character. So to decode you need to take two characters and join them together and then look for that value in your Numbers list, that's all you've missed.
So
So
repeat (length of (Number))Of course this is inefficient since it will check against every value in Numbers even if it has already found a match.
change [input Scanner v] by [2]
set [List scanner v] to [0]
set [encoded-value v] to (join (letter ((input Scanner) - (1)) of (Number)) (letter (input Scanner) of (Number))
repeat (length of [Numbers v])
change [List scanner v] by [1]
if <(encoded-value) = (item (List scanner) of [Numbers v])> then
set [Decode Output v] to (join [] []) // as you currently have - fill in the gaps
end
end
end
- BowWhalley
-
Scratcher
100+ posts
Encode/Decode
When you encode you're saving two digits to represent a character. So to decode you need to take two characters and join them together and then look for that value in your Numbers list, that's all you've missed.
Sorepeat (length of (Number))Of course this is inefficient since it will check against every value in Numbers even if it has already found a match.
change [input Scanner v] by [2]
set [List scanner v] to [0]
set [encoded-value v] to (join (letter ((input Scanner) - (1)) of (Number)) (letter (input Scanner) of (Number))
repeat (length of [Numbers v])
change [List scanner v] by [1]
if <(encoded-value) = (item (List scanner) of [Numbers v])> then
set [Decode Output v] to (join [] []) // as you currently have - fill in the gaps
end
end
end
THANKYOU very much! I got it to work!
- Discussion Forums
- » Help with Scripts
-
» Encode/Decode



