My project Buried Treasure
http://scratch.mit.edu/projects/Paddle2See/113483
implements a 52 element array using local variables in a sprite called Array for storage and a small set of global variables (Array Length, Array Index, Array Value) to pass arguments for value storage and retrieval. A set of scripts are also included with the sprite for typical array operations
Array Zero - Place zero values at all locations
Array Put Value - Stores the value in Array Value at location Array Index
Array Get Value - Retrieves the value at location Array Index to Array Value
plus a series of scripts originally set up for a card game I was working on (hence the 52 elements!) which I won't get into here but may be valuable to others so I have left them in.
The storage elements are accessed with nested IF-THEN-ELSE blocks arranged in a slightly unbalanced binary tree arrangement so tests are minimized during storage and retrieval. Access time is still not speedy but acceptable for most applications.
The Buried Treasure project uses the array to keep track of all the items the user discovers during a treasure hunt so they can be reviewed whenever the user desires. The code was very tedious to construct and is very resuable and might prove useful in a variety of applications.
I found that simply exporting the Array sprite from the original card game project, then importing to my project worked fine - AFTER I SAVED AND REOPENED the project. Apparently, Scratch needs the save and reopen to sort out the variables so they work properly.
Last edited by Paddle2See (2008-03-07 09:34:48)
Offline