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

#1 2013-03-27 17:18:34

Zottenpedj
New Scratcher
Registered: 2013-03-27
Posts: 3

pause / resume

Hello,

I am making a game in byob, and altough there is an pause button above the "game screen" I would like to program one that pauses/resumes the game when i press "p".
can anyone tell or even show me how to do that?

many thanx,
Arne

Offline

 

#2 2013-03-27 19:41:37

Maltese_Falcon
Scratcher
Registered: 2013-03-25
Posts: 100+

Re: pause / resume

When (P key) pressed
if <(Play/Pause) = [1]
 Set (Play/Pause) to [0]
end
if <(Play/Pause) = [0]>
 Set (Play/Pause) to [1]
Then have all of your stuff set up so:
if <(Play/Pause) = [0]>
Make all of the keys that control your sprite don't do anything
end
if <(Play/Pause) = [1]>
Have all of your keys do what they want.
end

Offline

 

#3 2013-03-27 19:44:37

Maltese_Falcon
Scratcher
Registered: 2013-03-25
Posts: 100+

Re: pause / resume

Oops. I messed up.

When (P key) pressed
if <(Play/Pause) = [1]>
 Set (Play/Pause) to [0]
end
if <(Play/Pause) = [0]>
 Set (Play/Pause) to [1]
Then have all of your stuff set up so:
if <(Play/Pause) = [0]>
 Make all of the keys that control your sprite don't do anything
end
if <(Play/Pause) = [1]>
Have all of your keys do what they want.
end

Offline

 

#4 2013-03-27 19:55:44

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: pause / resume

Maltese_Falcon wrote:

Oops. I messed up.

When key [p v] pressed
forever
 if <(Play/Pause) = [1]>
  Set [Play/Pause v] to [0]
 end
 if <(Play/Pause) = [0]>
  Set [Play/Pause v] to [1]
 end
end
Then have all of your stuff set up so:
 forever
  if <(Play/Pause) = [0]>
  Make all of the keys that control your sprite don't do anything
 end
  if <(Play/Pause) = [1]>
   Have all of your keys do what they want.
  end
end

Fixed  smile

With regards
     
           ~7734f

Last edited by 7734f (2013-03-27 19:57:44)


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#5 2013-03-28 09:23:25

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: pause / resume

when key [p] pressed
if <(pause) > [0]>
 set [pause] to [0]
else
 set [pause] to [1]
wait until <not <key [p] pressed>>
if <(pause) = [0]>
 code of your sprite
Simpler and avoid pause spaz.

Offline

 

#6 2013-03-28 09:28:03

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: pause / resume

xlk wrote:

when key [p] pressed
if <(pause) > [0]>
 set [pause] to [0]
else
 set [pause] to [1]
end
wait until <not <key [p] pressed>>
if <(pause) = [0]>
 code of your sprite
Simpler and avoid pause spaz.

that's what I meant...

Offline

 

#7 2013-03-28 09:32:06

Zottenpedj
New Scratcher
Registered: 2013-03-27
Posts: 3

Re: pause / resume

thanks a lot everybody!!!  smile

Offline

 

#8 2013-03-28 15:24:26

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: pause / resume

Small improvement, because as far as I know the when key pressed hats work like the when I recieve hat blocks in that they restart whenever the key is pressed (even if it is waiting) so if you put

forever
if <key [p v] pressed? >
set [pause v] to (( 1 ) - (pause))
end
wait until <not <key [p v]pressed?>>
under whatever hat block starts the bit of your game that you want to pause that should hopefully work better.
Also if your script is very long / slow it would be better (although a bit lengthy) to put:
if <(pause) = [0]>
first block of your code
else
if <(pause) = [0]>
second block of your code
else
if <(pause) = [0]>
third block of your code
else
if <(pause) = [0]>
fourth block of your code
else
if <(pause) = [0]>
fifthe block of your code
else
end
end
end
end
end
smile

Offline

 

#9 2013-03-28 15:27:43

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: pause / resume

Sorry I meant:

if <(pause) = [0]>
first block of code
if <(pause) = [0]>
second block of code
if <(pause) = [0]>
third block of code
e.t.c.
end
end
end
.

Offline

 

#10 2013-03-28 15:35:41

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: pause / resume

Another way you could do it is:

when gf clicked
set [pause] to [false]
when [p] key pressed
set [pause] to [true]
wait until <key [p] pressed>
set [pause] to [false]
hope this works  smile

Last edited by topazdragonlord (2013-03-28 15:36:38)


http://i45.tinypic.com/idumbk.png

Offline

 

Board footer