Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Converting usernames to numbers, please help
- AProductions
-
500+ posts
Converting usernames to numbers, please help
How could I convert a username into numbers for use in a variable? In other words how could I translate letters to numbers? Please help
- RUBIXS
-
60 posts
Converting usernames to numbers, please help
I'm not sure if it will work, but you could assign each letter a number a=1 b=2 and so on. then add the name into a list. split the list into separate lists, one for each letter. then use the numbers to convert it into one big number and combine that into a list or variable. Never tried it before but its worth a try 

- DadOfMrLog
-
1000+ posts
Converting usernames to numbers, please help
There are many examples of projects that encode strings into numbers - to use in cloud variables, for example. I suspect searching for ‘encode’/'encoding'/'encoder' will give you plenty of hits.
In my Cloud Var Ping Test project I have a couple of encoder/decoder blocks that do exactly what you want, so you could take a look there (and it has the useful extra feature that the encoder can tell apart upper & lower case - but note you need to have all the sprite's 52 costumes in with it for that to work - and it doesn't use any lists at all, instead doing it all via string manipulation…)
I didn't bother putting loads of ‘odd’ extra characters (like ¡€¢∞§¶•ªºœ∑…) into my set of allowed characters (just wanted to encode into two digits, so a set of only 100 characters allowed). But I've seen a couple of other encoders out there that try to include lots of extra possible characters, should you need them (though I think the basic principle of what I've done is probably straightforward enough for you to extend, anyway…)
In my Cloud Var Ping Test project I have a couple of encoder/decoder blocks that do exactly what you want, so you could take a look there (and it has the useful extra feature that the encoder can tell apart upper & lower case - but note you need to have all the sprite's 52 costumes in with it for that to work - and it doesn't use any lists at all, instead doing it all via string manipulation…)
I didn't bother putting loads of ‘odd’ extra characters (like ¡€¢∞§¶•ªºœ∑…) into my set of allowed characters (just wanted to encode into two digits, so a set of only 100 characters allowed). But I've seen a couple of other encoders out there that try to include lots of extra possible characters, should you need them (though I think the basic principle of what I've done is probably straightforward enough for you to extend, anyway…)
Last edited by DadOfMrLog (June 28, 2013 02:58:27)
- eastons
-
25 posts
Converting usernames to numbers, please help
Check out:
http://scratch.mit.edu/projects/11132259/
Converts username to a numeric string.
This example only uses alphabet letters and 0-9 but can be expanded by adding references to the alpha variable
eastons
http://scratch.mit.edu/projects/11132259/
Converts username to a numeric string.
This example only uses alphabet letters and 0-9 but can be expanded by adding references to the alpha variable
eastons
Last edited by eastons (June 28, 2013 03:19:21)
- greenflash
-
18 posts
Converting usernames to numbers, please help
I'm not sure if it will work, but you could assign each letter a number a=1 b=2 and so on. then add the name into a list. split the list into separate lists, one for each letter. then use the numbers to convert it into one big number and combine that into a list or variable. Never tried it before but its worth a try
This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
- dracae
-
1000+ posts
Converting usernames to numbers, please help
Say if you had TA, with (T = 20) and (A = 1), then TA = 201!I'm not sure if it will work, but you could assign each letter a number a=1 b=2 and so on. then add the name into a list. split the list into separate lists, one for each letter. then use the numbers to convert it into one big number and combine that into a list or variable. Never tried it before but its worth a try
This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
But 201 can be (B = 2) and (A = 1) = BA!
Last edited by dracae (June 28, 2013 23:00:03)
- kola2
-
100+ posts
Converting usernames to numbers, please help
Converting usernames to numbers is 100% possible, you just have to use 2 letter'd numbers like 01, 02, 03 all the way up to 99 (Or you can use 3 letter'd numbers, but 2 letter'd is alot more easy)
- mitchboy
-
1000+ posts
Converting usernames to numbers, please help
Actually, TA would be 2001 and BA would be 0201.Say if you had TA, with (T = 20) and (A = 1), then TA = 201!I'm not sure if it will work, but you could assign each letter a number a=1 b=2 and so on. then add the name into a list. split the list into separate lists, one for each letter. then use the numbers to convert it into one big number and combine that into a list or variable. Never tried it before but its worth a try
This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
But 201 can be (B = 2) and (A = 1) = BA!
- dracae
-
1000+ posts
Converting usernames to numbers, please help
What system are YOU using?Actually, TA would be 2001 and BA would be 0201.Say if you had TA, with (T = 20) and (A = 1), then TA = 201!I'm not sure if it will work, but you could assign each letter a number a=1 b=2 and so on. then add the name into a list. split the list into separate lists, one for each letter. then use the numbers to convert it into one big number and combine that into a list or variable. Never tried it before but its worth a try
This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
But 201 can be (B = 2) and (A = 1) = BA!
- DadOfMrLog
-
1000+ posts
Converting usernames to numbers, please help
Yeah, use leading zeros for letters that give numbers less than ten, so you always get two digits.
BUT… when you first get the digit you must from then on treat it ONLY as a string, NOT as a number (i.e. don't do maths on it) - otherwise it will ditch the leading zero again.
If you want to encode each letter into two digits, then you'll probably need to just about fill all 100 characters - meaning use “00” to “99” to refer to each character - so you will have to beware of the leading zero problem, as above.
However, if you go for even more than 100 characters, then you'd encode into three digits. You're unlikely to have 1000 characters, so you can just encode a character into three digits from “100” to “999” (so your first letter encodes as “100”), and that way don't have to worry about leading zeros.
Take your pick…
BUT… when you first get the digit you must from then on treat it ONLY as a string, NOT as a number (i.e. don't do maths on it) - otherwise it will ditch the leading zero again.
If you want to encode each letter into two digits, then you'll probably need to just about fill all 100 characters - meaning use “00” to “99” to refer to each character - so you will have to beware of the leading zero problem, as above.
However, if you go for even more than 100 characters, then you'd encode into three digits. You're unlikely to have 1000 characters, so you can just encode a character into three digits from “100” to “999” (so your first letter encodes as “100”), and that way don't have to worry about leading zeros.
Take your pick…

Last edited by DadOfMrLog (June 29, 2013 08:04:38)
- mitchboy
-
1000+ posts
Converting usernames to numbers, please help
His system…What system are YOU using?Actually, TA would be 2001 and BA would be 0201.Say if you had TA, with (T = 20) and (A = 1), then TA = 201! This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
But 201 can be (B = 2) and (A = 1) = BA!
His system encodes A as 01, B as 02, T as 20, etc. It should then decode it the same way, so 0201 would decode as BA and 2001 would decode as TA.
- dracae
-
1000+ posts
Converting usernames to numbers, please help
Ok, I though A was just 1, not 01 for the system you were using…His system…What system are YOU using?Actually, TA would be 2001 and BA would be 0201.Say if you had TA, with (T = 20) and (A = 1), then TA = 201! This general idea should work, but the only trouble is that for a number like “111” there are two possible interpretations– is is AAA? KA? AK?
The way around this would be to put a “0” in front of the one digit numbers, so A is 01… then you can see that 0111 is AK (01 and 11)
But 201 can be (B = 2) and (A = 1) = BA!
His system encodes A as 01, B as 02, T as 20, etc. It should then decode it the same way, so 0201 would decode as BA and 2001 would decode as TA.

- dinosaur_a
-
20 posts
Converting usernames to numbers, please help
How could I convert a username into numbers for use in a variable? In other words how could I translate letters to numbers? Please help
- ThebroofScratch
-
29 posts
Converting usernames to numbers, please help
@AProductions I had a quick snoop and test, I found one and I modified it and put it in one of my projects. I'll put links for original and my modified one. How could I convert a username into numbers for use in a variable? In other words how could I translate letters to numbers? Please help
Just so you know, in mine ConvertUser is convert it back, ConvertUsername is to convert it to numbers. On Extreme Ninja Runner, ConvertHiScore is convert it back, and ConvertUserame is convert it to numbers. That one needs a high score thing so i recommened mine. Hope this helped!




Mine: https://scratch.mit.edu/projects/90573207/
Extreme Ninja Runner: https://scratch.mit.edu/projects/45836888/
Last edited by ThebroofScratch (Jan. 23, 2016 20:02:01)
- Deathlord101
-
2 posts
Converting usernames to numbers, please help
Last edited by Deathlord101 (Feb. 16, 2017 14:24:53)
- Deathlord101
-
2 posts
Converting usernames to numbers, please help
Last edited by Deathlord101 (Feb. 16, 2017 14:25:46)
- 25mgreen
-
8 posts
Converting usernames to numbers, please help
How do you convert it back to numbers and letters?
- deck26
-
1000+ posts
Converting usernames to numbers, please help
Please try to avoid necroposting, better to create a new topic. How do you convert it back to numbers and letters?
Decoding is simpler though. Take two digits from your input and they represent the number of a character (either in a list or using the letter n of textstring method). Use the join block to join each character to what you have so far as you decode.
- Powerr_Electron
-
8 posts
Converting usernames to numbers, please help
Hey AProductions,
It is possible to make the user's username a variable,
Scratch already makes it a variable by default, so you can use the sample code below for an idea.
Benjamin Case
It is possible to make the user's username a variable,

Thank you,
Benjamin Case
- marcelzietek2006
-
500+ posts
Converting usernames to numbers, please help
Please don't necropost Hey AProductions,
It is possible to make the user's username a variable,Scratch already makes it a variable by default, so you can use the sample code below for an idea.
Thank you,
Benjamin Case
- Discussion Forums
- » Help with Scripts
-
» Converting usernames to numbers, please help