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

#1 2011-05-02 00:24:45

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Attaching Values to Broadcasts

I think that it would be extremely useful, with potentially a very large number of these uses, to have a sort of way to attach a variable to a broadcast.
Additionally, to broadcast to a specific sprite.

so, for instance, you could have a block that says:
{ Broadcast |message| to |Sprite1| }
{ Broadcast |message| to |All| }
{ Broadcast |message| to |Stage| }

and for attaching a value, I'm not sure what the most user-friendly way to do it would be, but something like:
{ Broadcast |message ##| with value [3] }
{ Broadcast |message ##| with value [hello] }
{ Broadcast |message ## ##| with values [hello] , [world] }
{ Broadcast |add ## to ##| with values [-3.1] , [63.98] }

and it interprets any broadcast with a ## in it as including an attached value.
I'm not sure how you would get this to work well with putting an expression in the |message| field instead of selecting a dropdown... but you could probably make it work by doing it an entirely different way in which you don't have to attach a certain number of values to each broadcast, and you don't have to receive that number either.

anyways, to receiving:
:When I receive |message ##| , storing a value to |var1| :
:When I receive |message ##| , storing values to |var1| , |var2| :

so, what do you think?

Offline

 

#2 2011-05-02 00:27:58

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

Re: Attaching Values to Broadcasts

HUGE SUPPORT!!!!  big_smile
I've wanted this since forever and have tried coding it too.  hmm

Offline

 

#3 2011-05-02 01:01:48

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Re: Attaching Values to Broadcasts

I will add this to scratch suggestions then I guess...
I voted for http://suggest.scratch.mit.edu/forums/60449-suggestions/suggestions/1623323-broadcast-to-sprite?ref=title but now I'm out of votes.

Last edited by DarthPickley (2011-05-02 01:04:36)

Offline

 

#4 2011-05-02 01:05:11

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Attaching Values to Broadcasts

Yesss, then Scratch would have something that are more like normal functions ie:

public class Hypotenuse {

    public static double calculate(double a, double b) {
        return Math.sqrt(a*a + b*b);
    }
}

I do think it should be separate from broadcasts and not just an add on tho.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2011-05-02 01:10:52

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

Re: Attaching Values to Broadcasts

Or maybe just a (broadcasted value) reporter.

Offline

 

#6 2011-05-02 01:21:01

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Attaching Values to Broadcasts

Issues with putting this as a broadcast would be that, many script can be activated by a broadcast, so which scripts get which variables?

I think this would be better as a build your own block feature.

Say this was not round but instead spin, a block that spins a sprite for the number of seconds you put in

<round( 3

This would spin for 3 seconds

You would also be able to build blocks that return values

<abs(


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#7 2011-05-02 01:27:34

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Re: Attaching Values to Broadcasts

archmage wrote:

Yesss, then Scratch would have something that are more like normal functions ie:

public class Hypotenuse {

    public static double calculate(double a, double b) {
        return Math.sqrt(a*a + b*b);
    }
}

I do think it should be separate from broadcasts and not just an add on tho.

well, if we were allowed to have Classes in Scratch, then, I mean, so much would be possible. Multiplayer would be simple: just create a new instance of a multiplayer group class. It would be like the clone block, but different... somehow.

but I highly doubt that scratch will support classes. BYOB3 doesn't even support classes.

well, I was thinking more like,
not only CALLING the phone number of the other sprite, but leaving it a message as well.
(see this to understand what I mean)

I mean, it is a way for two sprites to communicate with each other. It is just an improvement on broadcasts, you can broadcast "hello"

Offline

 

#8 2011-05-02 01:38:27

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Attaching Values to Broadcasts

Ummm functions are different from classes,  that was just a java example, and java requires you to do a class declaration to run that script.

Still the issue of multiple scripts that are called to with the same broadcast still creates an issue.

I understand your problem with the phone example and I think that custom blocks can provide a better solution. For example, a custom block for your example could look like this:

call (sprite dropdown menu) with message (insert text here)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#9 2011-05-02 01:50:35

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Re: Attaching Values to Broadcasts

archmage wrote:

Issues with putting this as a broadcast would be that, many script can be activated by a broadcast, so which scripts get which variables?

I think this would be better as a build your own block feature.

Say this was not round but instead spin, a block that spins a sprite for the number of seconds you put in
[blocks]
<round( 3

This would spin for 3 seconds

You would also be able to build blocks that return values

<abs([/blocks]

well, it would be good in BYOB, but I was just thinking that for the Receive hat block, I didn't want to have to do such foreign things as upvars, so I said, when I receive, store values into my variables.

It is like you are sending data from one sprite to another.

{ broadcast |Send ##| to |Sprite1| with value [10 5 25 90 3 24 6 9] }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When I receive |Send ##| and accept value to |var1|:
  { parse (var1) }


In BYOB3 actually, you have something called "launch" or "run", where you can essentially run or launch (run means wait until done; launch means don't wait) a block of another sprite, with inputs, or an input list. you can also call it.

Offline

 

#10 2011-05-02 19:01:41

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Attaching Values to Broadcasts

You mean like sending an argument with a broadcast? That would be a good idea! How would it work though? Would there be added variables provided for the receiving script?


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer