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

#1 2012-05-03 11:59:06

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Pause function

I'm working on adding a pause function to my game (here), but the code I used for the movement of the enemies makes it so that it will always do that movement
The script for enemy movement is:
Forever
---Glide [pick random 3 to 5] secs to x [pick random -225 to 225] and y [pick random -40 to 180]
So that they glide around the screen randomly, but that code overwrites anything else, so even if I tell it to wait for "pause" variable to be true, it still moves. Does anyone have any code idea that either a) make the enemies do the same movement but will stop when it's paused or b) a way to make the current code respond to "pause" being true.

Thanks


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#2 2012-05-03 12:05:49

shiguy101
Scratcher
Registered: 2010-11-17
Posts: 1000+

Re: Pause function

SD7 wrote:

I'm working on adding a pause function to my game (here), but the code I used for the movement of the enemies makes it so that it will always do that movement
The script for enemy movement is:
Forever
---Glide [pick random 3 to 5] secs to x [pick random -225 to 225] and y [pick random -40 to 180]
So that they glide around the screen randomly, but that code overwrites anything else, so even if I tell it to wait for "pause" variable to be true, it still moves. Does anyone have any code idea that either a) make the enemies do the same movement but will stop when it's paused or b) a way to make the current code respond to "pause" being true.

Thanks

Forever
if
pause
=
true
Glide

Offline

 

#3 2012-05-03 12:14:56

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Pause function

That's exactly what I have, but takes about a second and a half to actually stop them. And then they don't all stop at once- you click pause and (there's three enemies), first stops, then second one stops, then the third, not all at once.


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#4 2012-05-03 12:18:15

shiguy101
Scratcher
Registered: 2010-11-17
Posts: 1000+

Re: Pause function

Forever
Glide
if
pause
=
true
stop all

Last edited by shiguy101 (2012-05-03 12:18:55)

Offline

 

#5 2012-05-03 12:24:11

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Pause function

But then if you click the pause button again, will it resume where it left off? I figured it would restart the game, like clicking the flag again (well, he11, I figured since it says stop all, the pause button wouldn't work anymore, because it's stopped)


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#6 2012-05-03 12:27:38

shiguy101
Scratcher
Registered: 2010-11-17
Posts: 1000+

Re: Pause function

shiguy101 wrote:

Forever
Glide
if
pause
=
true
stop script

this is what I meant

Offline

 

#7 2012-05-03 12:28:46

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Pause function

So pressing pause again with restart the script?


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#8 2012-05-03 12:33:14

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Pause function

Tried that, didn't do anything.
I did try
Forever
-- if <(PAUSE) = [0]>
------- if <(Red 1 Move) = [true]>
---------------Glide

But again, that didn't stop them instantly, they glided around for about a second before coming to a stop


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#9 2012-05-03 12:34:34

shiguy101
Scratcher
Registered: 2010-11-17
Posts: 1000+

Re: Pause function

you may also need

When
Sprite1
Clicked
set
pause
to
true
broadcast
start
When I receive
start
Glide

Last edited by shiguy101 (2012-05-03 12:40:46)

Offline

 

#10 2012-05-03 12:59:22

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Pause function

I don't know if that applies to the code I have... have you downloaded the project?


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#11 2012-05-03 13:56:20

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Pause function

The problem is that the glide block takes the full 3 to 5 seconds before moving on to the next block in the stack -- so if you set pause to true when the sprite has just started gliding, it can take a full 5 seconds before it actually stops.

To avoid this, you can make your own glide method that mimics the block, but also checks for the pause variable every so often.

Offline

 

#12 2012-05-03 14:07:55

itsmomito
Scratcher
Registered: 2008-03-28
Posts: 100+

Re: Pause function

Fixed it SD7  smile

Forever
if
Bomber Move
=
True
Set
X Destin
to
pick random
-170
to
170
Set
Y Destin
to
pick random
50
to
150
repeat until
abs
of
x position
-
X Destin
<
5
and
abs
of
y position
-
Y Destin
=
5
Change the equal sign to less than. Somehow I couldn't when typing scratch blocks
if
PAUSE
=
0
if
x position
<
X Destin
Change x by
1.5
if
x position
>
X Destin
Change x by
-1.5
if
y position
>
Y Destin
Change y by
-1.5
if
y position
<
Y Destin
Change y by
1.5

Last edited by itsmomito (2012-05-03 14:40:19)

Offline

 

Board footer