Discuss Scratch
- Discussion Forums
- » Suggestions
- » Matrices / 2D arrays?
- gatzke
-
100+ posts
Matrices / 2D arrays?
There are many cases where a 2D array (matrix) of data would make sense.
You can do 2D with a single dimension, but it takes a good bit more effort to do so in your code. Supporting it natively in Scratch would allow for some cool applications.
I put together a matrix package for basic linear algebra, but the code is a mess IMHO because of the requirement to do things with only 1D arrays.
http://scratch.mit.edu/projects/24145965/
Now if someone would just implement HSL Scratch could take over the world…
You can do 2D with a single dimension, but it takes a good bit more effort to do so in your code. Supporting it natively in Scratch would allow for some cool applications.
I put together a matrix package for basic linear algebra, but the code is a mess IMHO because of the requirement to do things with only 1D arrays.
http://scratch.mit.edu/projects/24145965/
Now if someone would just implement HSL Scratch could take over the world…
Last edited by gatzke (March 12, 2015 13:28:45)
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
Why don't you make a fortran emulator?
Anyway, you can emulate 2d lists with 1d lists by using things like
Anyway, you can emulate 2d lists with 1d lists by using things like
- gatzke
-
100+ posts
Matrices / 2D arrays?
I know you can do 2D with 1D, it just adds an extra layer of confusion by not having a native data type.
Maybe the issue is you can't pass a list variable into a subroutine? Is that correct? Just numeric values and strings? Or am I mistaken.
Yes, a FORTRAN or COBOL emulator in Scratch would be a beautiful thing. But only if it runs off punchcards.
Maybe the issue is you can't pass a list variable into a subroutine? Is that correct? Just numeric values and strings? Or am I mistaken.
Yes, a FORTRAN or COBOL emulator in Scratch would be a beautiful thing. But only if it runs off punchcards.
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
You need some hax, but it can be done Maybe the issue is you can't pass a list variable into a subroutine? Is that correct? Just numeric values and strings? Or am I mistaken.
Then replace the block spec with
["procDef", "set %n %n of %m.list to %s", ...] ^^^this
See @nXIII's spreadsheet for more stuff you can hack into custom block specs
- gatzke
-
100+ posts
Matrices / 2D arrays?
That is amazing but scary. Not sure where you make that change or how you make that change. In the Scratch text file? It doesn't error check and cut that right out if you are running online?
In my library, I assumed you initialized the size of each matrix, so each matrix had a integer ID starting at 1. That initialization initialized a workspace list, adding a 0 for each element, and added size information to other lists. That way all you needed was the matrix id integer value. All the data is buried in lists that you never have to work with. You can set and retrieve element information from the list.
In my library, I assumed you initialized the size of each matrix, so each matrix had a integer ID starting at 1. That initialization initialized a workspace list, adding a 0 for each element, and added size information to other lists. That way all you needed was the matrix id integer value. All the data is buried in lists that you never have to work with. You can set and retrieve element information from the list.
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
It's not scary at all. Json hacking is easy, just download the project from the editor, open it with an archive manager, open project.json in your favorite text editor, and hack away. Once you're done, upload the project back to the editor.
- Zro716
-
1000+ posts
Matrices / 2D arrays?
you don't even need an archive manager: It's not scary at all. Json hacking is easy, just download the project from the editor, open it with an archive manager, open project.json in your favorite text editor, and hack away. Once you're done, upload the project back to the editor.
1. download project as a ZIP file
2. open contents and copy the project.json to your desktop
3. open the file to notepad
4. ctrl+f, “%m” and add .list to the end of them
5. save the file
6. move the file back to the zip folder, replace file in destination
7. change project extension to .sb2
8. profit
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
3complicated5me. I use 7-zip, which temporarily extracts the files and runs notepad++, then packs the archive automatically once I'm done editing. No need to do more work than necessary.you don't even need an archive manager: It's not scary at all. Json hacking is easy, just download the project from the editor, open it with an archive manager, open project.json in your favorite text editor, and hack away. Once you're done, upload the project back to the editor.
1. download project as a ZIP file
2. open contents and copy the project.json to your desktop
3. open the file to notepad
4. ctrl+f, “%m” and add .list to the end of them
5. save the file
6. move the file back to the zip folder, replace file in destination
7. change project extension to .sb2
8. profit
- gatzke
-
100+ posts
Matrices / 2D arrays?
But if the ST ever decides to parse your projects for completeness or correctness this mod would get your work bounced methinks.
I will try to work within the bounds they have provided for me :-(
I will try to work within the bounds they have provided for me :-(
- JayZX535
-
62 posts
Matrices / 2D arrays?
I second this– you can kinda replicate it using what scratch has now, but it takes a ton of code and is a pain in the neck. Actual 2-d arrays would be marvelous.
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
Although they say only projects made with the Scratch editor are allowed to be shared, I don't see them enforcing the rule. Plus, djdolphin is making But if the ST ever decides to parse your projects for completeness or correctness this mod would get your work bounced methinks.Scratchception
I will try to work within the bounds they have provided for me :-(

Last edited by MegaApuTurkUltra (March 14, 2015 16:36:05)
- comp09
-
1000+ posts
Matrices / 2D arrays?
I think you meant this project: https://scratch.mit.edu/projects/50169416/Although they say only projects made with the Scratch editor are allowed to be shared, I don't see them enforcing the rule. Plus, djdolphin is making But if the ST ever decides to parse your projects for completeness or correctness this mod would get your work bounced methinks.Scratchception
I will try to work within the bounds they have provided for me :-(
- MegaApuTurkUltra
-
1000+ posts
Matrices / 2D arrays?
ooook, thanks again Scratch search for not displaying relevant results on top. I'll fix itI think you meant this project: https://scratch.mit.edu/projects/50169416/Although they say only projects made with the Scratch editor are allowed to be shared, I don't see them enforcing the rule. Plus, djdolphin is making But if the ST ever decides to parse your projects for completeness or correctness this mod would get your work bounced methinks.Scratchception
I will try to work within the bounds they have provided for me :-(
Sorry djdolphin!
- Cyoce
-
500+ posts
Matrices / 2D arrays?
Here's how it should work: accept lists as a data structure! Allow the `item of ` block to accept dropdown lists!
Then, you can do:
- gatzke
-
100+ posts
Matrices / 2D arrays?
I have seen that, but I think it leads to some complexity issues and maybe some syntax implementation problems. You give too much freedom and some things become very dangerous and others stop working I think.
0D, 1D, and 2D data types would not be a huge stretch to add.
0D, 1D, and 2D data types would not be a huge stretch to add.
- theonlygusti
-
1000+ posts
Matrices / 2D arrays?
Especially as 2 of those are already within scratch 0D, 1D, and 2D data types would not be a huge stretch to add.

You don't need a new data type to make multidimensional arrays though, no programming language (of which I k ow) does that: they are all just arrays of arrays.
- gatzke
-
100+ posts
Matrices / 2D arrays?
Correct. Got me. 
In MATLAB, everything is an N dimensional array (pretty much).
A 2D array is just pretty darn useful in a lot of cases without opening up the can of works that lists of lists could make.
People get numbers. People get lists of numbers. People get 2D storage of numbers. CS majors get lists of lists.
I am not trying to infer that CS majors are not people.

In MATLAB, everything is an N dimensional array (pretty much).
A 2D array is just pretty darn useful in a lot of cases without opening up the can of works that lists of lists could make.
People get numbers. People get lists of numbers. People get 2D storage of numbers. CS majors get lists of lists.
I am not trying to infer that CS majors are not people.

- Rex208
-
500+ posts
Matrices / 2D arrays?
This. I second this– you can kinda replicate it using what scratch has now, but it takes a ton of code and is a pain in the neck. Actual 2-d arrays would be marvelous.
- Discussion Forums
- » Suggestions
-
» Matrices / 2D arrays?