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

#1 2012-12-22 15:47:56

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

broadcasts and variables

When I try to use the repeat until block with a variable, the loop isn't broken when the variable evaluates to true. The value is broadcast from the other sprite script and change at the end of the script. After the change I tried to rebroadcast the variable but that didn't work either. What am I not getting?

Offline

 

#2 2012-12-22 20:50:48

mathfreak231
Scratcher
Registered: 2012-10-24
Posts: 80

Re: broadcasts and variables

Post script. I can't quite understand you.


~This sig is false~
I'm on teh wiki!

Offline

 

#3 2012-12-23 18:56:30

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

Re: broadcasts and variables

I want sprite one to control the action of sprite 2. First the script for sprite 1, then for sprite 2.

when gf clicked
set size to (100) %
go to x: (-160) y: (90)
set [sound_exist] to [0]
repeat (20)
   move (7) steps
   next costume
   move (7) steps
end
if <touching [sprite 3] ?>
   go to x: (160) y sad -90)
   set size to (50) %
end
broadcast [sound_exist]
play sound [Pink-Get This] until done
change [sound_exist] by (1)
broadcast [sound_exist]
glide (10) secs to x: (-160) y: (90)
stop script
[/scratchblocks]

when I receive [sound_exist]
show variable [sound_exist]
switch to costume [jodi1]
go to x: (-130) y: (-13)
set size to (100) %
repeat until <[sound_exist] = [1]
   switch to costume [jodi2]
   wait (0.25) secs
   switch to costume [jodi1]
   wait (0.25) secs
end
go to x: (-167) y: (-63)
set size to (50) %
stop script
the problem is the repeat loop never ends. I am under the impression that when the variable evaluates true that the loop is broken. Where am i going wrong? Thank you for your help.

Offline

 

#4 2012-12-23 19:02:28

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

Re: broadcasts and variables

Must hawhen gf clicked
set size to (100) %
go to x: (-160) y: (90)
set [sound_exist] to [0]
repeat (20)
   move (7) steps
   next costume
   move (7) steps
end
if <touching [sprite 3] ?>
   go to x: (160) y: (-90)
   set size to (50) %
end
broadcast [sound_exist]
play sound [Pink-Get This] until done
change [sound_exist] by (1)
broadcast [sound_exist]
glide (10) secs to x: (-160) y: (90)
stop script
[/scratchblocks]ve made a typo with the first script: let me try again.

Offline

 

#5 2012-12-23 19:07:15

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

Re: broadcasts and variables

and again!

when gf clicked
set size to (100) %
go to x: (-160) y: (90)
set [sound_exist] to [0]
repeat (20)
   move (7) steps
   next costume
   move (7) steps
end
if <touching [sprite 3] ?>
   go to x: (160) y: (-90)
   set size to (50) %
end
broadcast [sound_exist]
play sound [Pink-Get This] until done
change [sound_exist] by (1)
broadcast [sound_exist]
glide (10) secs to x: (-160) y: (90)
stop script

Offline

 

#6 2012-12-24 04:58:15

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

For the second one, repeat until what?


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#7 2012-12-24 05:01:13

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

when I receive [sound_exist v]
show variable [sound_exist v]
switch to costume [jodi1 v]
go to x: (-130) y: (-13)
set size to (100) %
repeat until <(sound_exist) = [1]>// Is this right
   switch to costume [jodi2 v]
   wait (0.25) secs
   switch to costume [jodi1 v]
   wait (0.25) secs
end
go to x: (-167) y: (-63)
set size to (50) %
stop script
Ahh Fixed

Last edited by letmethink (2012-12-25 05:48:14)


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#8 2012-12-24 05:02:41

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

How long is the music?


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#9 2012-12-24 20:25:31

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

Re: broadcasts and variables

Music is 3 minutes 14 seconds

Offline

 

#10 2012-12-24 20:34:17

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

Re: broadcasts and variables

but I can't get my operator to look like yours. Mine has pointy sides on it and the string is on a white background. I think that is the problem but don't know how to fix it.

Offline

 

#11 2012-12-24 20:48:36

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

Re: broadcasts and variables

Let me try and duplicate the operator block I am getting:

<[sound_exist] = [0]>
let's see if I understand how this works.

Offline

 

#12 2012-12-24 20:54:10

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

Re: broadcasts and variables

Closer, but I still don't get the pointy ends...Maybe I need a space between the greater than symbol and the bracket.

< [sound_exist] = [0] >
let's see what happens now

Offline

 

#13 2012-12-24 20:58:58

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

Re: broadcasts and variables

Nope, still no pointy ends! I'm gonna go get a pizza!

Offline

 

#14 2012-12-24 21:05:42

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

Re: broadcasts and variables

The problem may be the variable is changing too many times too fast. Try putting

<(sound_exist)>(0)>

Last edited by mmww (2012-12-24 21:06:25)


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

 

#15 2012-12-25 05:46:38

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

rickvh wrote:

Closer, but I still don't get the pointy ends...Maybe I need a space between the greater than symbol and the bracket.

< [sound_exist] = [0] >
let's see what happens now

Try using normal brackets like this,

<(sound_exist)=[0]>

Which makes

<(sound_exist)=[0]>
instead of square brackets like this

< [sound_exist] = [0] >

Which makes
< [sound_exist] = [0] >
I hope I helped, letmethink


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#16 2012-12-25 05:52:53

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

when gf clicked
set size to (100) %
go to x: (-160) y: (90)
set [sound_exist] to [0]
repeat (20)
   move (7) steps
   next costume
   move (7) steps
end
if <touching [sprite 3] ?>
   go to x: (160) y: (-90)
   set size to (50) %
end
broadcast [sound_exist]
play sound [Pink-Get This] until done
change [sound_exist] by (1)
broadcast [sound_exist] // Is this needed?
glide (10) secs to x: (-160) y: (90)
stop script
Oh and by the way you can't get pointy ends, it is one of the limitations of the scratchblock bbcode.


Can I see the project so I can work out the error

Last edited by letmethink (2012-12-25 05:54:03)


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#17 2012-12-25 20:01:13

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

Re: broadcasts and variables

When you write the code out in the forum the operator looks correct when you post, but when I fill in the square white boxes of the = operator in the Scratch program the block has pointy ends and a square white rectangle with the string in it.
Also, I don't know if the second broadcast block is needed. I assumed when the value changed that I had to re-broadcast to effect the change since the script stops after the next block. Once the broadcast block is triggered by the script does it broadcast continuously and reflect changes in value when they occur or does it broadcast just once with the value the variable is at when triggered?
And, I'd be glad to send you the project file. What's the best way to do so? E-mail it to you as an attachment? Or is there some way to post it here besides writing out the scripts for all three sprites? I am going to write out the script for one of the sprites with the offending operator in it to see what it looks like when I post it. If it looks as it should when posted I may have a bug in my Scratch program. If so, it would reflect the story of my life! Thank for your help!

Offline

 

#18 2012-12-25 20:18:12

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

Re: broadcasts and variables

Let's see what happens!

when I receive [sound_exist v]
show variable [sound_exist v]
if < (sound_exist) = [0] >
   go to x: [-130] y: [-13]
   set size to [100] %
   forever
      switch to costume [jodi2 v]
      wait [0.25] secs
      switch to costume [jodi1 v]
      wait [0.25] secs
   end
else
   stop script
end

Offline

 

#19 2012-12-25 20:24:22

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

Re: broadcasts and variables

This is what it should look like in my scratch program's scripts panel, but doesn't! The green operator has pointy ends and sound_exist is in a white rectangle. Is there any way of checking the bbcode in my Scratch program?

Offline

 

#20 2012-12-26 04:03:31

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

The operator is meant to have pointy ends,

Are you sure that you made sound_exist a variable?


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#21 2012-12-27 21:24:08

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

Re: broadcasts and variables

yes I did. do you drop the variable block into the operator block? or type the variable name into the operator block, which is what I did.

Offline

 

#22 2012-12-27 22:09:27

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

Re: broadcasts and variables

OMG! That is what you do! I totally didn't understand this! Thanks for hanging with me! Now I can continue.

Offline

 

#23 2012-12-28 04:04:04

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: broadcasts and variables

I happy I could help, I thought your typed variable looked suspicious.

smile


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

Board footer