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

#1 2012-06-26 09:57:18

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Trouble with save/load code

http://scratch.mit.edu/projects/sci_test/2632539

I, in reply to applejack, wrote:

You can draw on the stage in 3 shapes. They can be at 10px intervals, and they are 20px square, which means they can overlap. That works fine. It stores the value of each space on the stage (10px apart) in a list functioning as an array, with length 1728 (48*36). This part usually works, but it is a bit iffy. Save/load completely doesn't work though. Save is supposed to iterate through the list, keeping track of the previous value. It packs them up together. If it finds the same value several times in a row, say 0, 102 times, it would do 0|102| instead of 0 102 times. This doesn't always work. Load is supposed to interpret the code, so if it finds a pipe, it finds the value between the pipe, and repeats the previous character (stored in memory) that amount of times. This doesn't work right.

That is what i'm having trouble with.
Anyone got a solution? Ask if you need more info.

Offline

 

#2 2012-06-26 18:36:03

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Trouble with save/load code

I encode this way.

If A exists 7 times, 7A is added to the list.

So the list looks like this: B,A,7A,4B,13C,

When I begin, I set the (iterations) variable to [] - nothing. When I unpack, I check to see if the letter(counter) of (code)  is a number or a letter.

If it's a number, set the iterations variable to (join (iterations) (number)). If its a letter, I repeat (iterations) for stamping that letter costume (if iterations = [], set it to 1), and then set (iterations) to [].

This may or may not hold a solution, this is just the way I do it.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#3 2012-06-26 19:05:41

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Trouble with save/load code

I believe this is a method used a lot in "lossless" data compression (all the compressed data can be retrieved exactly in its original state without corruption).  The PNG image format, for example, uses "lossless" compression algorithms.  JPEGs, on the other hand, often have fuzziness because of the "lossy" compression techniques used. 

The name of the particular method you're looking at is Run-Length Encoding.  Hopefully that page will give you a bit more information.

Last edited by amcerbu (2012-06-26 19:05:57)

Offline

 

#4 2012-06-26 20:42:51

Haiming
Scratcher
Registered: 2011-08-20
Posts: 1000+

Re: Trouble with save/load code

I don't know how to help, but YOU need help?!  lol

Offline

 

#5 2012-06-26 20:51:52

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Trouble with save/load code

Haiming wrote:

I don't know how to help, but YOU need help?!  lol

Everyone needs help at some point.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

Board footer