Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Number to String
- MCAnimator3D
-
500+ posts
Number to String
Hello. I'm trying to make a cloud list and I have the components in my head, but in ran into a problem when I was changing the username which was correctly converted to a number back into a string value. Each number getting put into the cloud variable has 2 digits. For example:
…and goes through the whole alphabet and numbers. The “username in numbers” list gets put into a cloud variable then I try to switch all of the numbers from the cloud variable back to a string. Since each number is a 2 digit number, I can't really figure out how to change the “counter” variable to the right value. When I run the script, this is what my username comes out with: accccaadiaccabaeahccd. Here's the Int to String script:
Last edited by MCAnimator3D (Nov. 26, 2013 20:48:36)
- drmcw
-
1000+ posts
Number to String
01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
- JAVAProgramming
-
100+ posts
Number to String
They aren't letters, there numbers.. 01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
And drmcw is right, you need to check 2 numbers at a time, and not just one.
And in you're real project, you aren't using the sensing Username variable, right?
Last edited by JAVAProgramming (Nov. 26, 2013 21:14:07)
- drmcw
-
1000+ posts
Number to String
If you're using the letter of block then they're letters!They aren't letters, there numbers.. 01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
And drmcw is right, you need to check 2 numbers at a time, and not just one.
- JAVAProgramming
-
100+ posts
Number to String
But the computer doesn't know any better, But, we as humans, know that 0- 9 are not letters, but numbers.If you're using the letter of block then they're letters!They aren't letters, there numbers.. 01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
And drmcw is right, you need to check 2 numbers at a time, and not just one.
- lederniersamourai
-
500+ posts
Number to String
what he says is that you have to do this:
Of course, the counter value should not go up to the end of the string but until the middle of it.
Of course, the counter value should not go up to the end of the string but until the middle of it.
- MCAnimator3D
-
500+ posts
Number to String
Thanks! It makes sense now! what he says is that you have to do this:
Of course, the counter value should not go up to the end of the string but until the middle of it.

- lederniersamourai
-
500+ posts
Number to String
Now you have understood that, you might consider to put the alphabet in a string variable (called, e.g., abc) and then use “letter (join …) of abc” which will remove all your “if … then” You can also put chars others than alphabet in that string.
If you understand that, you can use that string to remove all “if then” when you encode the name into digits: just iterate on the string with “letter idx of abc” and when reaching the letter to encode, just use the idx to store it in the cloud variable. To encod idx as a two digit number, just use “join floor(idx/10) (idx mod 10)” or use an if idy < 10 then .. else …“ The iteration is as quick as your sequence of ”if … then"
This is less errorprone and easier to modify if necessary.
If you understand that, you can use that string to remove all “if then” when you encode the name into digits: just iterate on the string with “letter idx of abc” and when reaching the letter to encode, just use the idx to store it in the cloud variable. To encod idx as a two digit number, just use “join floor(idx/10) (idx mod 10)” or use an if idy < 10 then .. else …“ The iteration is as quick as your sequence of ”if … then"
This is less errorprone and easier to modify if necessary.
- Discussion Forums
- » Help with Scripts
-
» Number to String