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

#1 2012-12-10 18:46:24

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

broadcasts and variables

When I broadcast a variable name does the value broadcast with it? I am assuming so but my script doesn't doesn't behave like it. I initially created a variable called sound exist  then set sound exist = 0 in the script of one sprite. Then when sprite one does it's thing I broadcast sound exist. Then play sound until done and then change sound exist by one.
    In sprite two I created an if else statement: if: sound exist = 0 a forever loop is started, else: sprite two goes to a location and stays there. The problem is: even though the script for sprite one set the variable to 0 It doesn't seem to be evaluated by the if-else statement in sprite two and it bypasses the whole block.
    Also, is the broadcast continuous or must you rebroadcast every time a value changes?

Offline

 

#2 2012-12-10 22:01:31

obsidiousshade
Scratcher
Registered: 2011-07-03
Posts: 17

Re: broadcasts and variables

All right, your wording's a little confusing but I think I get what you're saying. When you broadcast a variable by taking the variable name from the variable block list, the round orange block with the name on it, and placing it on the dropdown list and snapping it into that space, it broadcasts the value of the variable. For instance, the script

broadcast [sound exist]
will broadcast the value of the variable at the time the script is executed. What is the hat block of the script that tells the sprite to see if "sound exist" equals zero. You know, is it, when green flag clicked, when I recieve..., or something like that?


Growing Darkness: An Andromeda Production
http://i49.tinypic.com/qqd01c.jpg

Offline

 

#3 2012-12-22 15:57:39

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: broadcasts and variables

I used the when I receive hat block. and the equals operator for the variable

Offline

 

#4 2012-12-23 11:35:22

mmww
Scratcher
Registered: 2010-01-14
Posts: 500+

Re: broadcasts and variables

I would try:


when flag clicked
forever
if <(sound exist)=(0)>
broadcast [play v]
else
broadcast [stop v]
end
end
Then on another sprite:

when I receive [play v]
Play sound [music v] until done
when I receive [stop v]
forever 
stop all sounds
end

Last edited by mmww (2012-12-23 11:36:09)


http://i.imgur.com/AWFFO.pnghttp://www.weebly.com/uploads/1/0/1/4/10146167/4363061_orig.png Save the cheese!
I am http://blocks.scratchr.org/API.php?action=onlineStatus&amp;user=mmww

Offline

 

#5 2012-12-23 14:10:29

obsidiousshade
Scratcher
Registered: 2011-07-03
Posts: 17

Re: broadcasts and variables

mmww's script should work. Try that and let us know if you have any more problems.


Growing Darkness: An Andromeda Production
http://i49.tinypic.com/qqd01c.jpg

Offline

 

#6 2012-12-24 16:35:56

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: broadcasts and variables

The thing is: I am trying to control the actions of another sprite not the sound . However, I think I can apply this strategy to that end. Thanks! Also, I didn't know you could have multiple scripts for the same sprite... I'm learning!

Offline

 

#7 2012-12-24 19:03:08

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: broadcasts and variables

When I try to use statements that require operators such as if, if-else, repeat until and wait until the operator doesn't seem to get evaluated. I set the value of a variable in the script of another sprite and broadcast the variable name. Does the value not get broadcast as well? Or am I using the operators incorrectly? I use a string on one side and an integer on the other:

<(sound_exist) = [0]>
The if statement works with the sensing function 'touching' though.

Also, does the ' stop all ' controller affect all sprites?

Offline

 

#8 2012-12-24 19:17:45

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: broadcasts and variables

My operator doesn't look like the one in my last post either! It has pointy ends and the string is on a white background like the integer. do I need to put the variable name in parenthesis when I fill in the little white boxes of the = operator? what am I not getting?

Offline

 

#9 2012-12-24 20:15:36

rickvh
New Scratcher
Registered: 2012-12-10
Posts: 21

Re: broadcasts and variables

In going through the help topics I answered my own question concerning the Stop All controller. But there is nothing I can do to get the if-else statement to evaluate my "sound_exist=0" operator. I even tried to set sound_exist to 0 immediately before the if-else block and it still went right through to the else section. ???

Offline

 

Board footer