Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Does Not Wait
- doonkoo
- Scratcher
100+ posts
Does Not Wait
I am working on another version of my Asteroids game, but while the script for earth says to broadcast and wait, it does not wait!
And now for the Asteroid script:
when gf clicked
set variables and stuff
forever
set [selector v] to (pick random (1) to (5))
set [acceptable asteroid v] to (selector)
broadcast [Fire v] and wait
end
And now for the Asteroid script:
when I receive [Fire v]Did I do anything wrong? It should be working… Shouldn't it?
create clone of [myself v]
when I start as a clone
show
if <(acceptable asteroid) = [1]> then
go to x:(-180) y:(120)
if <(Level) < [10]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
else
if <(Level) > [9]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
end
end
end
if <(acceptable asteroid) = [2]> then
go to x:(-180) y:(60)
if <(Level) < [10]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
else
if <(Level) > [9]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
end
end
end
if <(acceptable asteroid) = [3]> then
go to x:(-180) y:(0)
if <(Level) < [10]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
else
if <(Level) > [9]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
end
end
end
if <(acceptable asteroid) = [4]> then
go to x:(-180) y:(120)
if <(Level) < [10]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
else
if <(Level) > [9]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
end
end
end
if <(acceptable asteroid) = [5]> then
go to x:(-180) y:(120)
if <(Level) < [10]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
else
if <(Level) > [9]> then
repeat until <<touching [Laser v]?> or <<touching [Spaceship v]?> or <touching [_edge_ v]?>>>
move (Level) steps
if <touching [Laser v]?> then
hide
end
if <touching [Spaceship v]?> then
hide
change [Lives v] by (-1)
end
if <touching [_edge_ v]?> then
hide
change [Level v] by (-1)
end
end
delete this clone
end
end
end
“I am pleased a book on science competes with the memoirs of pop stars. Maybe there is some hope for the human race.”
-Stephen Hawking
“Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world.”
-Albert Einstein
“I have noticed people who claim everything is predestined, and that there is nothing we can do to change it, look before they cross the road.”
-Stephen Hawking
- doonkoo
- Scratcher
100+ posts
Does Not Wait
then finishes the broadcast. You'll have to find a workaroundoh. is there one? When you broadcast that, it simply creates the clone and then the broadcast is finished. I think you're under the intention that it runs the entire “when I start as a clone” script and
“I am pleased a book on science competes with the memoirs of pop stars. Maybe there is some hope for the human race.”
-Stephen Hawking
“Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world.”
-Albert Einstein
“I have noticed people who claim everything is predestined, and that there is nothing we can do to change it, look before they cross the road.”
-Stephen Hawking
- scubajerry
- Scratcher
1000+ posts
Does Not Wait
say [You need to do it with a variable.]
Set [Wait_Var] to [1]
Broadcast [Fire]
Wait until [Wait_Var = 0]
At the end of clone
Set [Wait_var] to [0]
Last edited by scubajerry (Sept. 12, 2013 22:27:52)
- turkey3
- Scratcher
1000+ posts
Does Not Wait
You can use a variable, so right before the sprite is cloned, it sets the variable to 1, and before it's deleted, set it back to 0. Then, instead ofthen finishes the broadcast. You'll have to find a workaroundoh. is there one? When you broadcast that, it simply creates the clone and then the broadcast is finished. I think you're under the intention that it runs the entire “when I start as a clone” script and
broadcast [fire v] and waitAlso, instead of broadcasting, receiving, and cloning yourself, why not just clone yourself in the first place? It could save a millisecond.
set [variable v] to (1) //instead of the above, do this
broadcast [fire]
wait until <(variable) = [0]> //and add "set variable to 0" before the clone is delete
- Splodgey
- Scratcher
100+ posts
Does Not Wait
broadcast [fire v] and wait
when i receive [fire v]
create clone of [myself v]
broadcast [clone startup v] and wait
when i start as a clone
set [clone? v] to (1)
when i receive [clone startup v]
if <(clone) = [1]> then
clone scripts
It may have some problems when you have multiple clones at once, however…
There's a that wait makes it go to the broadcast, and when it finishes running the code, it comes back. If you want it to wait 5 seconds, you'd have to add said block. If you want to make it wait for it to wait for a certain event, then you will need to use a variable as a custom reporter block.
wait (1) secsblock…
Last edited by Splodgey (Sept. 13, 2013 17:54:27)
Ever wondered why there's no text box? Or why you can make sprites “say” stuff, but not display pure text? Click here! Now v1.3, includes links!
Text Box, Calculator, AlphaSorter & Case Sensor
Have a large-scale Minecraft project and you want to know how much raw materials you need to craft the “ingredients”? Click here!
Minecraft PvP Weapon Vs Armour Calculator/Simulator
- Discussion Forums
- » Help with Scripts
- » Does Not Wait