Topic.
Offline
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.
Offline
It is quite difficult. Scratch doesn't have arrays so you have to get creative.
Offline
heybrian1 wrote:
Do you mean Matrix?
Matrices is the plural of Matrix.
Offline
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
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)
Offline
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.
Offline
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
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
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.
Offline
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
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)
Offline
Alright, that's smart. The only thing is I probably need something that holds a lot more than 7 digits...
Offline
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.
Offline
Alright, I'll try that. Thanks again.
Offline
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.
Offline
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
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.
Offline