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

#1 2008-03-07 09:29:57

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

Crude Array Implementation

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)


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

Offline

 

#2 2008-03-07 17:20:13

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Crude Array Implementation

That project is soo fun to play despite being frightfully instructive to study, I recommend it for everybody!


Jens Mönig

Offline

 

Board footer