This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » Advanced Topics
  •  » Scratch Source Code - Modify mapping of block flags to functionality.

#1 2010-07-20 11:20:41

lpiloto
New Scratcher
Registered: 2010-07-15
Posts: 5

Scratch Source Code - Modify mapping of block flags to functionality.

Hi All,

I've been working with the Scratch source code to create a specialized set of blocks that are specific to a particular application and which should be as simplified as possible for the end user. I have some Arduino code written in Processing that listens for changes in specific variables by listening for broadcasts from Scratch and activates a particular electronic device. One of those is a 'BrewStatus' variable.  The goal is to have an end user be able to easily manipulate the 'BrewStatus' variable without any prior setup.  In order to accomplish this, I created a new entry in the blockspecs array:

Code:

          ('startBrew'       -       startBrew)

where startBrew is a function I defined in the ScriptableScratchMorphs's instance space which uses hard-coded values in Scratch's "broadcast" method passing "BrewStatus" as the thing to be broadcasted and "On" as the value.  Using this method, I have successfully communicated with the Arduino and a button-press connected to the startBrew block will successfully turn on the electronic device via the Arduino.

Scratch and Processing can also communicate the other way around: Processing code can simulate a variable broadcast, lets call it var1 here.If there is a "When I receive (var1)" broadcast listener setup in Scratch, the Scratch code will be triggered by the Processing code.  In order to provide the simplest interface for our end users, I need to create a block that is hardcoded to fire when the Processing code broadcasts a change to a variable, BrewStatus.  Therefore, I need a block that says "When BrewStatus Changes" and will not require any setup from the user (i.e. picking from a dropdown menu of broadcast events).  I was hoping I could simply mimic the technique used for my startBrew block, i.e. override a 'whenReceiveBroadcast' method with a hardcoded value of 'BrewStatus' and take it from there.  HOWEVER, the code for broadcast receivers in blockSpecs is:

Code:

('when I receive %e'    #E       #-)

It seems that the broadcast-receiving functionality is achieved through use of the #E identifier and in conjunction with the '%e' string which creates the dropdown of available events.  Does anyone know where this functionality is defined? There are a variety of possible solutions foreseeable here.  If I could override the '#E' mapping, that would work.  If I could hardcode what gets passed to it (instead of the '%e') that would also work.

I know this has been long-winded, I thoroughly appreciate anyone that has taken the time to read this and especially anyone that could provide some assistance.

Cheers!

Offline

 

#2 2010-07-20 12:04:47

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Source Code - Modify mapping of block flags to functionality.

look at the <when I recieve |     |> block in the advanced topic forums. It may help you a bit!


You can now reach me on Twitter @johnnydean1_

Offline

 

#3 2010-07-20 12:48:20

lpiloto
New Scratcher
Registered: 2010-07-15
Posts: 5

Re: Scratch Source Code - Modify mapping of block flags to functionality.

Thank you for the suggestion.  I've looked at the block provided in this link and have managed to hardcode it to check if the specific BrewStatus variable is being broadcasted.

However, this is not the exact functionality I'm looking for as it simply provides a <   > shaped block that is a boolean reporter.  I need an event to be fired off, mimicking the functionality of the "When startFlag clicked" or "When I Receive [ ]" blocks.

Offline

 

#4 2010-07-20 12:52:26

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Source Code - Modify mapping of block flags to functionality.

Can you explain clearer?


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-07-20 12:54:08

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Scratch Source Code - Modify mapping of block flags to functionality.

BTW Hat blocks (At the top) are very confusing...

A hat block example:
[blocks]
<when green flag clicked>
[/blocks]


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2010-07-20 17:16:02

lpiloto
New Scratcher
Registered: 2010-07-15
Posts: 5

Re: Scratch Source Code - Modify mapping of block flags to functionality.

Basically, I just want a Hat Block that is programmed to be triggered when a hard-coded value (in this case 'BrewStatus') is broadcasted. I understand this functionality can be easily replicated by simply using the [blocks]<when I receive[ [/blocks], but it would require our end-user to select the 'BrewStatus' event from the dropdown list of broadcast events and this is counter-productive to the research I am doing.

My previous post elaborated on a block that allowed me to detect in an [blocks] <forever if>[/blocks] whether or not an event had fired by placing my custom block in the slot of the forever if block, but I need a HatBlock for the desired functionality.
I hope I have been clear enough, I'll be more than happy to elaborate more if necessary considering you're the only person thats commented and tried to help me thus far.

Cheers!

Offline

 

#7 2010-07-20 17:23:36

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Scratch Source Code - Modify mapping of block flags to functionality.

lpiloto wrote:

Basically, I just want a Hat Block that is programmed to be triggered when a hard-coded value (in this case 'BrewStatus') is broadcasted. I understand this functionality can be easily replicated by simply using the [blocks]<when I receive[ [/blocks], but it would require our end-user to select the 'BrewStatus' event from the dropdown list of broadcast events and this is counter-productive to the research I am doing.

My previous post elaborated on a block that allowed me to detect in an [blocks] <forever if>[/blocks] whether or not an event had fired by placing my custom block in the slot of the forever if block, but I need a HatBlock for the desired functionality.
I hope I have been clear enough, I'll be more than happy to elaborate more if necessary considering you're the only person thats commented and tried to help me thus far.

Cheers!

Hmmm, I might try this...


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 
  • Index
  •  » Advanced Topics
  •  » Scratch Source Code - Modify mapping of block flags to functionality.

Board footer