This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-02-22 09:40:27

ScipioBellorum
Scratcher
Registered: 2007-05-15
Posts: 94

Storing Letters in Bianry-Like code - Please Read and Assist

After much hard work, I have almost perfected binary-code-like storage for letter variables. It works like this:

Before I start, this is VERY compicated (or at least it is to me!). Know first that:
Bank 1's 'A' = 0
Bank 1's 'B' = 0
Bank 1's 'C' = 0.1
Bank 1's 'A' = 0
Bank 1's 'F' = 1
Bank 1's 'Stored' = 0

The keys are divided into groups of nine because the code can only manage numbers 1 - 9 becuase 10 is 1 and 0. Each group of nine is its own memory bank.

When a key is pressed, it sets its bank's 'L' to the coresponding number. Eg. A=1, B=2, I=9, J=1.

Keys ABCDE are pressed one after the other

Variable 'A' is set to 'L'
Variable 'L' is set to 0
Variable 'B' is set to <B x 10>
Variable 'C' is set to <C x 10>
Variable 'B' is changed by 'A'
Variable 'F' is changed by 1
Variable 'A' is set to 0
Variable 'B' is changed by 'A'
Variable 'Stored' is set to 'F'

In this way the letters are stored like so:
ABCDE will be stored in Bank 1's 'B' as 12345
Bank 1's 'C' will be 10000
Bank 1's 'F' will be 5


The information is retrieved when the 'space' key is pressed in the following way:
Variable 'E' is set to 'B'
Variable 'B' is set to <B x 10>
Variable 'C' is set to <C x 10>
Variable 'B' is changed by 1
Repeat until 'Stored' = 0
Variable 'D' is set to:
'B' divided by 'C' (123451 divided by 100000 = 1.23451)
minus
'B'/'C' mod 1 (1.23451 divided by 1 - 1 = 0.23451)
SO
'B'/'C' - 'B/C' mod 1 = (1.23451 - 0.23451) = 1 (Letter A which is sent to the typing bar)

Variable 'B' is set to:
'B' divided by 'C' (123451 divided by 100000 = 1.23451)
minus
Variable 'D'
which is 1.23451 - 1 = 0.23451
multipied by C (100000)
which is 0.23451 x 100000 = 23451

Variable 'C' is set to <C / 10> (100000/10 = 10000)
Variable 'Stored' is changed by -1 (5 - 1 = 4)

The retrieval process repeats Variable 'Stored' (5) times and then stops.

I have also implemented a code for letters J to R, which consists of another bank (Bank 2) containing letters J to R and a third bank (Bank Number) containing information that is sent to the typing bar telling it which Letter Bank to take its next letter from.
If I wrote AJBJCJ:
Bank 1's 'B' would be 123
Bank 2's 'B' would be 111
Bank Number's 'B' would be 121212 (Bank 1 (A), Bank 2 (J), Bank 1 (B) etc.)

In theory the sytem can hold an unlimited number of characters. However, for some reason, after the 17th character it refuses to continue and writes the remaining letters as a single letter so that ABCDEABCDEABCDEABCDEABCDE comes out as something like this: ABCDEABCDEABCDEABBBBBBBBB. After many rude words, I found out that it has something to do with the way the variable is stored in Scratch itself. Because it attempts to shorten it by storing it as 1.2345e19 it corrupts it somehow causing it stop at the 18th character when it encouters 464.3 it the place of 345.1.

Why does this happen? Can anyone help me with this? It is very, very, very annoying as the only other alternative I can think of (and have tried) is storing each letter in its own variable (L1 = H, L2 = E, L3= L, L4 = L, L5 = O,), which is an excelent system except for the fact that each variable must be created and added to an ever lengthening list. I have only reached 9 and already I've had enough!

Please help me!

SB

Last edited by ScipioBellorum (2008-05-03 09:25:54)


http://img393.imageshack.us/img393/339/logory8.png
                      The word processor for Scratch

Offline

 

#2 2008-02-22 12:28:04

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Storing Letters in Bianry-Like code - Please Read and Assist

If there is an upper limit to the length of the variable string, it sounds as if you will need to have a new variable after every 17th letter.

Though I am not quite sure what you are trying to do.  Store text?


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2008-02-22 12:40:43

ScipioBellorum
Scratcher
Registered: 2007-05-15
Posts: 94

Re: Storing Letters in Bianry-Like code - Please Read and Assist

Is there no other way? This would mean making say 20 variables for one paragraph. And yes (it worries me that I wrote all that and didn't make this clear...) I am trying to find a way of storing text in binary like code which can then be 'saved' and brought back again.

SB


http://img393.imageshack.us/img393/339/logory8.png
                      The word processor for Scratch

Offline

 

#4 2008-02-22 13:07:31

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Storing Letters in Bianry-Like code - Please Read and Assist

There is a limit to how many characters you can store in a number variable.  That is because the variables themselves are only allocated a given amount of storage space in the computer's memory.  Other projects that store a lot of characters have used the screen as storage space by encoding the charcters into small colored pixels that are stored on the screen using the pen or stamp functions.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2008-02-23 01:54:15

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Storing Letters in Bianry-Like code - Please Read and Assist

Yes, that might be a better option.  A strip 1 pixel tall across the bottom of the screen could store 480 letters, if you use 26 different colours.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#6 2008-02-23 03:36:21

ScipioBellorum
Scratcher
Registered: 2007-05-15
Posts: 94

Re: Storing Letters in Bianry-Like code - Please Read and Assist

That's brilliant!! I can't believe I didn't think of it. Thanks for your help guys, uch appreciated.

SB


http://img393.imageshack.us/img393/339/logory8.png
                      The word processor for Scratch

Offline

 

#7 2008-02-23 10:26:13

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Storing Letters in Bianry-Like code - Please Read and Assist

Using the screen as an array is not an obvious idea.  I did it a long time ago in my Simon game  http://scratch.mit.edu/projects/kevin_karplus/2158 , but I got the idea from John Maloney, who sent me e-mail about it 19 Dec 2006.

Offline

 

Board footer