Hello Scratch Forum,
Sorry, this might be a little long.
Background:
I am researching Scratch projects for Calvin College. This involves looking at many different Scratch projects and attempting to extract data from them such as the number of loops, if statements, or variables used in a project.
What I have done so far:
The "Write Multiple Project Summaries" feature has helped me get almost everything that I want.
The problem with my partial solution:
In the summary files, I have found no good way to quickly determine the number of sprite-specific variables used. I can get a rough estimate of all variables used by the number of times there is say a "change <"var"> by n", but I would like to be able to have something a bit more concrete. I was able to extract global variables by exploring and modifying a little code in Squeak to make "Remote Sensor Connections" enabled by default then writing a simple c++ client application and a script to open and close Scratch files. (When the "Remote Sensor Connections" are enabled and a connection is made, it dumps all of the global variables to the client).
Are there any ideas as to how I could get at these sprite-specific variables, or a less ugly way of getting to global variables?
-Andrew
Offline
If you know how many global and how many all, can't you just subtract global from all?
Offline
Thanks for the reply.
The problem is that I don't actually have a precise number for total variables. The only number I have with certainty is globals.
I think what I'll end up doing is writing something to scan for keywords associated with modifying variables(change <variable> by <number> or set <variable> to <number>) , then scan for distinct names and push each of those onto a (c++)vector and finally return the vector's size... at which point, I can subtract total-global to find the number of sprite-specific variables, but it seems awfully roundabout.
Offline
andrew_webster wrote:
Thanks for the reply.
The problem is that I don't actually have a precise number for total variables. The only number I have with certainty is globals.
I think what I'll end up doing is writing something to scan for keywords associated with modifying variables(change <variable> by <number> or set <variable> to <number>) , then scan for distinct names and push each of those onto a (c++)vector and finally return the vector's size... at which point, I can subtract total-global to find the number of sprite-specific variables, but it seems awfully roundabout.
That may be the only/easiest (
) way to do it.
BTW, it's SET <variable> TO <string>.
Why do you want this info?
Last edited by scimonster (2011-06-23 11:18:09)
Offline
The set of sprite-specific variables is kept in a Dictionary (name->value) in ScriptableScratchMorph class, called "vars" (the class ScratchSpriteMorph is a subclass of ScriptableScratchMorph and initializes its own dictionary through the message send "super initialize", which will execute ScriptableScratchMorph>>initialize). To get a sprite's specific variables you will have to get the sprite's reference and then iterate over this dictionary.
Offline
Baderous:
Thank you! I'm starting to get acclimated to Smalltalk. I got it to output to the Transcript. My next step is to throw that into the server code so that I can extract it for a bunch of projects easily.
scimonster:
For my research, I am looking for measurable differences in students' code between game and storytelling programs.
Offline
Update: I added the following to Scratch-Objects->ScriptableScratchMorph->private->printSummaryOn:
t1 nextPutAll: ' Variables';
crlf.
vars keysDo: [:t7 | t1 nextPutAll: ' ' , t7].
t1 nextPutAll: '';
crlf.
t1 nextPutAll: ' Lists';
crlf.
lists keysDo: [:t7 | t1 nextPutAll: ' ' , t7].
t1 nextPutAll: '';
crlf.Now when I "Write Project Summary", I see a list of variables and lists used with each sprite and globals show up under Stage. I would recommend that Scratch developers consider doing something like this for future releases.
I may also toy around with trying to extend the server feature to try to collect live data from students' programming.
Thanks for the help!
Offline
I believe the title comes from either how many posts I've made on these forums or how long I've been a member. I am a college senior studying computer science.
Keep going in programming and you will find that there are endless possibilities that are within your grasp. With a little research and time, you begin to realize that there really isn't any magic behind how computers and things work--and understanding even a little of that puts you miles ahead of the crowd.
Offline
andrew_webster wrote:
Update: I added the following to Scratch-Objects->ScriptableScratchMorph->private->printSummaryOn:
Code:
t1 nextPutAll: ' Variables'; crlf. vars keysDo: [:t7 | t1 nextPutAll: ' ' , t7]. t1 nextPutAll: ''; crlf. t1 nextPutAll: ' Lists'; crlf. lists keysDo: [:t7 | t1 nextPutAll: ' ' , t7]. t1 nextPutAll: ''; crlf.Now when I "Write Project Summary", I see a list of variables and lists used with each sprite and globals show up under Stage. I would recommend that Scratch developers consider doing something like this for future releases.
I may also toy around with trying to extend the server feature to try to collect live data from students' programming.
Thanks for the help!
May I use this code in my modification of Scratch, RAGE?
Offline
May I use this code in my modification of Scratch, RAGE?
Sure. Just put a comment in the code by it that has my name ("Andrew Webster") and "Calvin College Research".
Offline
andrew_webster wrote:
I believe the title comes from either how many posts I've made on these forums or how long I've been a member. I am a college senior studying computer science.
Keep going in programming and you will find that there are endless possibilities that are within your grasp. With a little research and time, you begin to realize that there really isn't any magic behind how computers and things work--and understanding even a little of that puts you miles ahead of the crowd.
That second paragraph is unimaginably philosophical -- may I quote it?
Offline
Sure. Glad you like it.
Offline
andrew_webster wrote:
Sure. Glad you like it.
I added it in part to my sig (it doesn't fit all). Thanks!
Offline