Discuss Scratch

MCAnimator3D
Scratcher
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:
ifitemcounterofdecompiled username=athenadd01tousername in numbers
…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:
iflettercounterofData=01thensetusernametojoinusernamea

Last edited by MCAnimator3D (Nov. 26, 2013 20:48:36)

drmcw
Scratcher
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
Scratcher
100+ posts

Number to String

drmcw wrote:

01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
They aren't letters, there numbers..

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
Scratcher
1000+ posts

Number to String

JAVAProgramming wrote:

drmcw wrote:

01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
They aren't letters, there numbers..

And drmcw is right, you need to check 2 numbers at a time, and not just one.
If you're using the letter of block then they're letters!
JAVAProgramming
Scratcher
100+ posts

Number to String

drmcw wrote:

JAVAProgramming wrote:

drmcw wrote:

01 isn't a letter. 0 is a letter and 1 is a letter but 01 is 2 letters.
They aren't letters, there numbers..

And drmcw is right, you need to check 2 numbers at a time, and not just one.
If you're using the letter of block then they're letters!
But the computer doesn't know any better, But, we as humans, know that 0- 9 are not letters, but numbers.
lederniersamourai
Scratcher
500+ posts

Number to String

what he says is that you have to do this:

ifjoinletter2*counter-1ofDataletter2*counterofData=01thensetusernametojoinusernamea

Of course, the counter value should not go up to the end of the string but until the middle of it.
MCAnimator3D
Scratcher
500+ posts

Number to String

lederniersamourai wrote:

what he says is that you have to do this:

ifjoinletter2*counter-1ofDataletter2*counterofData=01thensetusernametojoinusernamea

Of course, the counter value should not go up to the end of the string but until the middle of it.
Thanks! It makes sense now!
lederniersamourai
Scratcher
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.

Powered by DjangoBB