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

#1 2011-06-21 12:35:13

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Extracting Scratch Variables for Research

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

 

#2 2011-06-23 09:51:03

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Extracting Scratch Variables for Research

If you know how many global and how many all, can't you just subtract global from all?

Offline

 

#3 2011-06-23 11:13:46

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

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

 

#4 2011-06-23 11:17:53

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Extracting Scratch Variables for Research

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 ( yikes ) way to do it.  hmm
BTW, it's SET <variable> TO <string>.  wink

Why do you want this info?

Last edited by scimonster (2011-06-23 11:18:09)

Offline

 

#5 2011-06-23 12:48:02

Baderous
New Scratcher
Registered: 2011-04-14
Posts: 100+

Re: Extracting Scratch Variables for Research

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

 

#6 2011-06-23 16:20:03

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

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

 

#7 2011-06-24 12:03:35

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

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!

Offline

 

#8 2011-06-24 14:31:58

whizzer
Scratcher
Registered: 2008-05-27
Posts: 500+

Re: Extracting Scratch Variables for Research

Are you seriously a New Scratcher? I didn't catch half of what you said.


http://i46.tinypic.com/33df6me.png I'm whizzer0 for all things Minecraft.

Offline

 

#9 2011-06-24 14:48:25

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

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

 

#10 2011-06-24 15:10:20

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: Extracting Scratch Variables for Research

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?


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#11 2011-06-24 16:02:11

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

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

 

#12 2011-06-24 16:05:21

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: Extracting Scratch Variables for Research

Thanks! I will.  smile


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#13 2011-06-24 16:18:21

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Extracting Scratch Variables for Research

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

 

#14 2011-06-24 16:51:04

andrew_webster
New Scratcher
Registered: 2011-06-09
Posts: 8

Re: Extracting Scratch Variables for Research

Sure.  Glad you like it.

Offline

 

#15 2011-06-24 17:11:38

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Extracting Scratch Variables for Research

andrew_webster wrote:

Sure.  Glad you like it.

I added it in part to my sig (it doesn't fit all). Thanks!

Offline

 

Board footer