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

#1 2008-02-07 23:10:55

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Local "Broadcasts"

The idea of "private" broadcasts (where a specific sprite gets the "message") has come up in the past, and, I'll have to admit, I was skeptical about the idea.

However, I've recently seen the utility of having a "broadcast" that is only received "internally".  The new "block" would be just like a broadcast, but would only be "heard" by scripts in the sprite that made the "local broadcast".  Perhaps instead of a "Broadcast", it would be a "Call" or a "Whisper".  This would be useful (at least to me) to break up code into functional chunks and to make sprites more re-useable.

For instance:

When working on "AI" for a game I'm currently fiddling with, I would like to have some randomness enter into decisions of what the "enemy" should do.  The program might  compare "AI postion" to the "target position" and apply a random number (with some "bias") to decide whether to move that direction in "x" and also in "y".  The logic would also have to check to see if the "AI" player was already close to the edge, if near the bottom of the screen, it would have to exclude moves in negative y, despite what the random number suggested to do.

So the logic is something like: If random number says move positive X and, If I'm not too close to the (positive x) edge, "find a positive X point to go to", else "find a negative X point to go to".

If random says move negative X and, If I'm not too close to the (negative X) edge, "find a negative X point to go to", else "find a positive X point to go to".

So, there are multiple places where a broadcast would work nicely: ("FindPos_Xpoint" and wait) or ("FindNeg_Xpoint" and wait).  These "subroutines" would compare where the AI player is, look at obstacles, target position, etc. and find the next "X" and "Y" for the AI sprite.  But, if these are "Broadcasts", I can't copy the AI sprite to make another one.  If they were "Calls" or "Whispers" (or whatever) that only the "calling" sprite could hear, the code could be neater and more reusable.

Thoughts?

-MrEd

Offline

 

#2 2008-02-08 03:49:46

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

Re: Local "Broadcasts"

I love the "whisper" terminology you just coined! Thinking about Scratch can be so inspiring.

I'm also in favor of introducing function calls to Scratch, especially ones which would be restricted within the code of each sprite, kind of like reusable (and possibly collapsable/expandable) block stacks, or a library system for your own custom blocks. You wouldn't even need any "whispering" broadcasting mechanism that way...


Jens Mönig

Offline

 

#3 2008-02-08 14:37:52

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Local "Broadcasts"

Both local function calls and "whispers" are a good idea.

The format I like for the whispers is
   send message to [pulldown list]

where the pulldown lists starts with
    all
    self
    stage
    -----
and then lists all sprites.

"Send message to all" is the current broadcast.
"Send message to self" is EdnaC's "whisper"
"Send message to ..." provides the specific message passing between sprites that other people have requested.

Offline

 

#4 2008-02-08 23:14:26

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Local "Broadcasts"

This also seems like a good idea "philosophically";  The idea of "Global" and "Local" variables has already been introduced to new programmers, local "broadcasts" is a natural extension.  The pulldown Kevin suggests (or perhaps a "radio button") would also be familiar to Scratch programmers, with "All" as the default.

I'm certain that I'll find a way to work around the example I used, either with broadcasts or some twists and turns of "if/thens" and setting variables, but the program would be much more readable if the often used code was something separate that could be called to.  (I'm all about using descriptive names for variables and broadcasts, which is why I whine so much about a rename function.)

-MrEd

Offline

 

Board footer