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

#1 2012-10-24 11:37:48

LifeLearner12
New Scratcher
Registered: 2012-10-18
Posts: 3

Ignore a broadcast

(1)
I'd like to be able to tel a sprite to ignore all broadcasts for awhile, then later tell it to start listening again.
Is this possible? (and how?)

(2)
Also, is there any type of advanced tutorial on broadcasts?
When they fire, somethings the sprite doesn't return back to previously running code after the broadcast is done (to the code I expected it to). I'd like to learn more about how broadcasts work.

Offline

 

#2 2012-10-24 11:42:20

Willpower
Scratcher
Registered: 2012-01-26
Posts: 1000+

Re: Ignore a broadcast

LifeLearner12 wrote:

(1)
I'd like to be able to tel a sprite to ignore all broadcasts for awhile, then later tell it to start listening again.
Is this possible? (and how?)

(2)
Also, is there any type of advanced tutorial on broadcasts?
When they fire, somethings the sprite doesn't return back to previously running code after the broadcast is done (to the code I expected it to). I'd like to learn more about how broadcasts work.

(1) if you do not tell a sprite to recieve a broadcast "when i recieve..." it will not answer it

(2) Erm- I'll see what i can do.. ahem!

Well, you use the "broadcast" block to send out a message to sprites and if you tell a sprite to answer it "when i recieve" it will. All other times it will ignore it

You may have noticed there are two types of broadcasting

"broadcast and wait" means it waits for the recieving sprite to complete the recieve task before it continues on it's script and plain "broadcast" means once it has broadcasted, it continues.

Was this any help? if you need me to explain anything just ask  big_smile


http://i49.tinypic.com/e84kdj.png

Offline

 

#3 2012-10-24 12:50:47

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Ignore a broadcast

1. In the "When I Receive" scripts, you can wrap with code with an if statement checking if the variable "receive_broadcasts" is true.

when I receive [a_broadcast v]
if <(receive_broadcasts) = [True]>
do something
end

Offline

 

#4 2012-10-24 13:17:40

notaloser
Scratcher
Registered: 2011-12-06
Posts: 100+

Re: Ignore a broadcast

OK, so I'm gonna try to explain what I think know want to know, magnie already did it, but lets go deeper!

Scripts of the 'Sending' sprite (sender):

When [space v] key pressed
broadcast [jump v]


When [q v] key pressed
set [receive_braodcast v] to [1] //'1' means yes and 0 means no, right now its listening.

When [w v] key pressed
set [receive_braodcast v] to [0] //you can set the q or w keys to any alphabet or condition.

Now for the blocks of the receiving sprite::


when i receive [jump v]
if <(receiving_braodcast) = [1]>
 move [10] steps //here you can type any script you want.
end


http://gifs.gifbin.com/1238409599_nom_nom.gifhttp://cdn3.lolzsquad.com/wp-content/uploads/2012/10/Come-here-I-want-to-tell-you-something.-.gif

Offline

 

#5 2012-10-24 16:46:01

LifeLearner12
New Scratcher
Registered: 2012-10-18
Posts: 3

Re: Ignore a broadcast

Thanks for the suggestions, but it doesn't solve the core issue.
Sometimes a sprite is responding to one broadcast, but it recieves a 2nd (different) broadcast and jumps to that one. but when it finishes response to the 2nd response, it doesn't always return to working on its response to the first broadcast.

I'd like to tell the sprite...
While working on the response to this broadcast, don't listen for any other broadcasts....

or someone force it to finish its current broadcast response BEFORE answering the second one.

Offline

 

#6 2012-10-25 07:45:56

notaloser
Scratcher
Registered: 2011-12-06
Posts: 100+

Re: Ignore a broadcast

All of these go in the receiving sprite:

when I receive [message1 v]
        set [receiving_broadcast? v] to [0]
        say [Do stuff]
        set [receiving_broadcast? v] to [1]
    
when I receive [message2 v]
        if <(receiving_broadcast?) = [1]>
        say [do stuff] 
        end

Last edited by notaloser (2012-10-25 07:49:01)


http://gifs.gifbin.com/1238409599_nom_nom.gifhttp://cdn3.lolzsquad.com/wp-content/uploads/2012/10/Come-here-I-want-to-tell-you-something.-.gif

Offline

 

#7 2012-10-25 10:27:18

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Ignore a broadcast

LifeLearner12 wrote:

Thanks for the suggestions, but it doesn't solve the core issue.
Sometimes a sprite is responding to one broadcast, but it recieves a 2nd (different) broadcast and jumps to that one. but when it finishes response to the 2nd response, it doesn't always return to working on its response to the first broadcast.

I'd like to tell the sprite...
While working on the response to this broadcast, don't listen for any other broadcasts....

or someone force it to finish its current broadcast response BEFORE answering the second one.

Ohh. Yeah, everything is basically "threaded" in Scratch (the advantages probably outweigh all the disadvantages), so one of the things you can do to [slightly] control the broadcasts, is use the [broadcast "message" and wait]. This block broadcasts the message and then waits until it finishes before continuing. But if you are using separate sprites to send messages, you'll need to probably build your own broadcast system (using variables or lists).

Offline

 

#8 2012-10-27 11:58:21

LifeLearner12
New Scratcher
Registered: 2012-10-18
Posts: 3

Re: Ignore a broadcast

Thanks everyone. Judging by the responses, the feature I am looking for just doesn't exist in Scratch - but you did give me some ideas on how to handle symptoms.

thanks  smile

Offline

 

Board footer