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

#1 2008-03-08 03:23:50

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Can you make lists and matrices?

Topic.

Offline

 

#2 2008-03-08 06:06:21

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

Re: Can you make lists and matrices?

Those data structures are not currently implemented in the Scratch language.  A lot of people have had fun trying to work around those limitations.  My latest project, Buried Treasure, uses a small array of 52 elements to keep track of items found by the user.  Check it out if you want to see the sort of effort involved in do-it-yourself data structure construction. 

http://scratch.mit.edu/projects/Paddle2See/113483

Other projects have used the screen to construct arrays and matrices or used numbers to store short lists of characters, that sort of thing.  If you are interested, I can get you links to those as well.


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

Offline

 

#3 2008-03-08 11:18:15

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Can you make lists and matrices?

It is quite difficult. Scratch doesn't have arrays so you have to get creative.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#4 2008-03-08 13:27:22

heybrian1
Scratcher
Registered: 2008-03-02
Posts: 100+

Re: Can you make lists and matrices?

Do you mean Matrix?


I am Heybrian. Yes, the "Ask me anything, for i am a pro scratcher" Thread IS mine.

Offline

 

#5 2008-03-08 13:30:02

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Can you make lists and matrices?

heybrian1 wrote:

Do you mean Matrix?

Matrices is the plural of Matrix.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#6 2008-03-08 13:30:51

heybrian1
Scratcher
Registered: 2008-03-02
Posts: 100+

Re: Can you make lists and matrices?

Oh i didn't know that. Strange. Very big difference in letters.


I am Heybrian. Yes, the "Ask me anything, for i am a pro scratcher" Thread IS mine.

Offline

 

#7 2008-03-09 01:05:08

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Paddle2See wrote:

Those data structures are not currently implemented in the Scratch language.  A lot of people have had fun trying to work around those limitations.  My latest project, Buried Treasure, uses a small array of 52 elements to keep track of items found by the user.  Check it out if you want to see the sort of effort involved in do-it-yourself data structure construction. 

http://scratch.mit.edu/projects/Paddle2See/113483

Other projects have used the screen to construct arrays and matrices or used numbers to store short lists of characters, that sort of thing.  If you are interested, I can get you links to those as well.

Interesting.  Thanks.  Can I see games that use screen constructs?  I know I won't be able to use it, but I'd like to see them anyways.  Maybe you'll have some suggestion as to what I should do.  Basically I know how to program a bunch of different maze algorithms, but the easiest way to program them is using lists or matrices.  There was one however that doesn't require either:
http://scratch.mit.edu/projects/thecooltodd/115384

heybrian1 wrote:

Oh i didn't know that. Strange. Very big difference in letters.

Yep.

Offline

 

#8 2008-03-09 06:45:40

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

Re: Can you make lists and matrices?

Well, in my own work (which I can find very easily, not that it's the best example, necessarily) there is Battleship

http://scratch.mit.edu/projects/Paddle2See/69459

which uses a mini-map on the screen (small yellow square) to store the computer's ship locations.  In any other language, I would use a matrix for this purpose.  The computer's ships are yellow and so is the mini-map so the user can't see the ships.  I recently learned that you can use the Ghost effect to make sprites invisible yet still responsive to the sensing blocks so there are better ways of hiding information storage in front of the user.

For an array, I have Recording Piano

http://scratch.mit.edu/projects/Paddle2See/56555

which stores the note pitch and duration as binary numbers along the bottom of the screen using single-pixel dots.  There are many other examples out there as well:

Stickman Movie Maker - Uses colors to remember a frame (be aware that the color pallet online works differently than the color pallet offline so this approach is risky)

http://scratch.mit.edu/projects/Yelmo/30133

Here's another excellent implementation of a color-based screen array

http://scratch.mit.edu/projects/1tchy/115745

Word Processing - Stores the characters you type on screen

http://scratch.mit.edu/projects/jay/21880

Simon - Stores flashing sequence on screen - one of the earliest implementations of a screen array

http://scratch.mit.edu/projects/kevin_karplus/2158

...and there are many other fine examples that other folks will probably post here to help you out some more.

Last edited by Paddle2See (2008-03-09 09:16:37)


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

Offline

 

#9 2008-03-09 08:29:59

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

Re: Can you make lists and matrices?

Another way of doing arrays, if every number stored is to be an positive integer between 0 and 1, is to use a single variable, then use a script to extract the 1s, 10s, 100s, 1000s etc.

EG one of my games keeps track of whether or not 10 enemies are alive or dead, and if alive, what height on the screen they appear at, by using a single variable that looks like

1040205632

Each digit refers to a different enemy, if zero they are dead, else they appear at a height that is a multiple of the digit.


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

 

#10 2008-03-09 14:21:04

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

Re: Can you make lists and matrices?

I used the screen trick very early on in my Simon game.  John Maloney suggested the idea to me in Dec 2006, and I think that the Simon game was the first on the web site to implement it.

http://scratch.mit.edu/projects/kevin_karplus/2158

Offline

 

#11 2008-03-09 16:02:19

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Wow, thanks Paddle2See.

Paddle2See wrote:

I recently learned that you can use the Ghost effect to make sprites invisible yet still responsive to the sensing blocks so there are better ways of hiding information storage in front of the user.

Wow, that sounds like exactly what I was looking for.

Anyways, getting off-topic, let me how the Kwik Kubric thing turns out. XD

Mayhem wrote:

Another way of doing arrays, if every number stored is to be an positive integer between 0 and 1, is to use a single variable, then use a script to extract the 1s, 10s, 100s, 1000s etc.

EG one of my games keeps track of whether or not 10 enemies are alive or dead, and if alive, what height on the screen they appear at, by using a single variable that looks like

1040205632

Each digit refers to a different enemy, if zero they are dead, else they appear at a height that is a multiple of the digit.

You are also a genius, that is another thing I needed XD
How many digits long can a number be?

kevin_karplus wrote:

I used the screen trick very early on in my Simon game.  John Maloney suggested the idea to me in Dec 2006, and I think that the Simon game was the first on the web site to implement it.

http://scratch.mit.edu/projects/kevin_karplus/2158

Wow, cool.

Offline

 

#12 2008-03-09 17:11:14

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

Re: Can you make lists and matrices?

Mayhem wrote:

Another way of doing arrays, if every number stored is to be an positive integer between 0 and 1, is to use a single variable, then use a script to extract the 1s, 10s, 100s, 1000s etc.

EG one of my games keeps track of whether or not 10 enemies are alive or dead, and if alive, what height on the screen they appear at, by using a single variable that looks like

1040205632

Each digit refers to a different enemy, if zero they are dead, else they appear at a height that is a multiple of the digit.

You are also a genius, that is another thing I needed XD
How many digits long can a number be?

It was not my idea originally.
I think the max length is 17 digits, but have not tested that.
You need to be careful with your numbers, as the default on scratch is to round to the nearest rather than rounding down.  So unless you tweak it, numbers of 5 or more will cause the next highest digit to round to one more than it actually is.


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

 

#13 2008-03-09 18:31:27

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Mayhem wrote:

It was not my idea originally.
I think the max length is 17 digits, but have not tested that.
You need to be careful with your numbers, as the default on scratch is to round to the nearest rather than rounding down.  So unless you tweak it, numbers of 5 or more will cause the next highest digit to round to one more than it actually is.

Oh, alright.  How exactly did you recall specific digits?  The units digit is by far the easiest by using mod.

Anyways, look up the Recursive Backtracker on http://www.astrolog.org/labyrnth/algrithm.htm
because that's basically the maze algorithm I need help on.  For some reason my program isn't working:
http://scratch.mit.edu/projects/thecooltodd/116730

Offline

 

#14 2008-03-10 01:58:55

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

Re: Can you make lists and matrices?

kevin_karplus wrote: wrote:

To get out the digit in the 1000s place of a non-negative number "x" use
       
( x/1000) ) mod 10

To zero out the digit in the 1000s place

     change x by - 1000 * ( (x/1000) mod 10)

To replace the digit in the 1000s place, first zero it out, then add 1000*digit

To make the formulae handle digit "DIGIT", (counting from the RIGHT), replace the "1000" with "10^(DIGIT-1)"

round ( x/( 10^( DIGIT-1) ) ) mod 10

So when DIGIT = 5, it returns the digit from the 10000 column, etc.

BTW You could try subtracting 0.5 before the rounding, which ought to make it return the actual digit even if the previous digit is greater than 5.

Last edited by Mayhem (2008-03-10 02:06:10)


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

 

#15 2008-03-10 03:15:17

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Alright, that's smart.  The only thing is I probably need something that holds a lot more than 7 digits...

Offline

 

#16 2008-03-10 04:50:25

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

Re: Can you make lists and matrices?

thecooltodd wrote:

Alright, that's smart.  The only thing is I probably need something that holds a lot more than 7 digits...

Well, there's still my manually constructed array in this project. 

http://scratch.mit.edu/projects/Paddle2See/113483

It's pretty easy to move the sprite containing the array (called Card Array) to another project; just export it to a file then drag and drop onto the project you want to use it in.  After that, save the project and reopen it to help Scratch sort out the variables.


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

Offline

 

#17 2008-03-11 02:25:48

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Alright, I'll try that. Thanks again.

Offline

 

#18 2008-03-11 05:27:02

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

Re: Can you make lists and matrices?

Here's some late breaking news!  Chalkmarrow has constructed a very slick 100 element matrix, using local variables in 10 sprites, that can be dimensioned any way you like as long as the total number of elements is less than or equal to 100.  Check it out at

http://scratch.mit.edu/projects/chalkmarrow/117305

It looks like it would scale up pretty easily if you needed more storage as well.  I'm not sure how the access speed compares to my single sprite array or a screen array.  That would be an interesting study for someone to make.


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

Offline

 

#19 2008-03-12 03:21:30

thecooltodd
Scratcher
Registered: 2008-03-08
Posts: 75

Re: Can you make lists and matrices?

Wow, that's smart how he did that.  Maybe I could try making something like that, but that's a lot of sprites and variables I'll need (21x28 matrix)

Offline

 

#20 2008-03-12 04:56:03

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

Re: Can you make lists and matrices?

thecooltodd wrote:

Wow, that's smart how he did that.  Maybe I could try making something like that, but that's a lot of sprites and variables I'll need (21x28 matrix)

Yep, you're looking at 588 elements - you would need 60 sprites, if you stuck to 10 elements per sprite.  That would be a bit of work to build...and you might not be happy with the speed once it was done.  What range of values are you trying to store in the matrix?  You might be better off with a screen array after all.


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

Offline

 

Board footer