Discuss Scratch

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!
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]
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
Did I do anything wrong? It should be working… Shouldn't it?


“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
turkey3
Scratcher
1000+ posts

Does Not Wait

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 then finishes the broadcast. You'll have to find a workaround

doonkoo
Scratcher
100+ posts

Does Not Wait

turkey3 wrote:

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 then finishes the broadcast. You'll have to find a workaround
oh. is there one?

“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

poof

Last edited by scubajerry (Sept. 12, 2013 22:28:38)

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

doonkoo wrote:

turkey3 wrote:

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 then finishes the broadcast. You'll have to find a workaround
oh. is there one?
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 of
broadcast [fire v] and wait

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
Also, instead of broadcasting, receiving, and cloning yourself, why not just clone yourself in the first place? It could save a millisecond.

xlk
Scratcher
100+ posts

Does Not Wait

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.

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…


xlk wrote:

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.
There's a
wait (1) secs
block…

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

Powered by DjangoBB