I used the space bar to start the game but I would also like to be able to use the space bar to pause the game also. Is it possible to do this in scratch?
Offline
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,
when gf clicked set variable [GAMESTART] to [false] if <key [space v] pressed> broadcast [START GAME] set variable [GAMESTART] to [true] end if <(GAMESTART]) = (true) broadcast [PAUSEGAME] end
Offline
mythbusteranimator wrote:
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,when gf clicked set [GAMESTART v] to [false] if <key [space v] pressed> broadcast [START GAME ] set [GAMESTART v] to [true] end if <(GAMESTART) = (true)> broadcast [PAUSEGAME] end
fixed
Offline
dvd4 wrote:
mythbusteranimator wrote:
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,when gf clicked set [GAMESTART v] to [false] if <key [space v] pressed> broadcast [START GAME ] set [GAMESTART v] to [true] end if <(GAMESTART) = (true)> broadcast [PAUSEGAME] endfixed
thx
Offline
Simpler way: (one that actually WORKS)
when key [space v] pressed do something when key [space v] pressed do something different
Offline
joefarebrother wrote:
Simpler way: (one that actually WORKS)
when key [space v] pressed do something when key [space v] pressed do something different
That would just do both.
Offline
mythbusteranimator wrote:
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,when gf clicked set [GAMESTART v] to [false] if <key [space v] pressed?> broadcast [START GAME v] set [GAMESTART v] to [true] end if <(GAMESTART) = (true)> broadcast [PAUSEGAME v] end
You realise that would start the game then instantly pause it, right?
joefarebrother wrote:
Simpler way: (one that actually WORKS)
when key [space v] pressed do something when key [space v] pressed do something different
That would just do them both at once, pretty much the same.
when gf clicked set [paused v] to [no] when key [space v] pressed if <(paused) = [yes]> set [paused v] to [no] else set [paused v] to [yes] end
Last edited by Splodgey (2012-10-26 11:23:24)
Offline
Thanks everyone!
Offline
mythbusteranimator wrote:
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,when gf clicked set [GAMESTART v] to [false] if <key [space v] pressed> broadcast [START GAME] set [GAMESTART v] to [true] end if <(GAMESTART]) = (true) broadcast [PAUSEGAME] end
Actually, not really, because it needs what I'm fixing...
when gf clicked set [GAMESTART v] to [false] repeat until <key [space v] pressed?> end broadcast [START GAME v] set [GAMESTART v] to [true]
when gf clicked forever if <(GAMESTART) = (true)> broadcast [PAUSEGAME v] end
Last edited by firedrake969_test (2012-10-29 11:37:15)
Offline
firedrake969_test wrote:
mythbusteranimator wrote:
Create a variable,
[GAMESTART]
When the green flag is clicked, have it set to "false".
So,when gf clicked set [GAMESTART v] to [false] if <key [space v] pressed> broadcast [START GAME] set [GAMESTART v] to [true] end if <(GAMESTART]) = (true) broadcast [PAUSEGAME] endActually, not really, because it needs what I'm fixing...
when gf clicked set [GAMESTART v] to [false] repeat until <key [space v] pressed?> end broadcast [START GAME v] set [GAMESTART v] to [true]when gf clicked forever if <(GAMESTART) = (true)> broadcast [PAUSEGAME v] end
Wait... wouldn't that last script make it pause once the game started?
I think this would work:
when gf clicked set [pause v] to [false] set [GAMESTART v] to [false] forever if <(GAMESTART) = [true]> if <(pause) = [false]> if <key [space v] pressed?> set [pause v] to [true] broadcast [pause v] end else if <key [space v] pressed?> broadcast [CONTINUE v] set [pause v] to [false] end end else if <key [space v] pressed?> broadcast [START GAME v]I know this is a long script, but it also has a continue feature in it. You wouldn't want to pause a game and not be able to continue, right?
Offline
if s/he's going to only press the space key once to start, you can avoid all of the ifs and variables (besides pause) if you do this:
when gf clicked set [paused v] to [1] //1 would be true, 0 would be false wait until <key [space v] pressed?> broadcast [STARTGAME v] //first time event wait until <not<key [space v] pressed?>> //making sure it doesn't automatically pause forever if <key [space v] pressed?> set [paused v] to <(1)-(paused)> //a small simple equation to alternate between 1 and 0 end
Last edited by TorbyFork234 (2012-10-30 23:17:52)
Offline
TorbyFork234 wrote:
if s/he's going to only press the space key once to start, you can avoid all of the ifs and variables (besides pause) if you do this:
when gf clicked set [paused v] to [0] //1 would be true, 0 would be false wait until <key [space v] pressed?> broadcast [STARTGAME v] //first time event wait until <not<key [space v] pressed?>> //making sure it doesn't automatically pause forever if <key [space v] pressed?> set [paused v] to <(1)-(paused)> //a small simple equation to alternate between 1 and 0 if <(paused) = [1]> pause scripts go here else unpause scripts go here end
I added the block that would make it do more than just change a variable. Also, if you don't want it to automatically pause, than why does it set pause to 1 when the game starts?
Offline
when gf clicked set [game started v] to [no] switch to background [press space to start v] when key [space v] pressed if <(game started) = [yes]> broadcast [pause game v] else set [game started v] to [yes] switch to background [playing the game v] maybe some more stuff end
Last edited by joefarebrother (2012-11-07 12:57:46)
Offline
This would work for a 1s1s project:
when gf clicked set [pause v] to [-1] wait until <key [space v] pressed?> forever if <(pause) = (-1)> GAME SCRIPT end if <key [space v] pressed?> set [pause v] to ((-1)*(pause)) endAnd this would work for a multi sprite script project:
when gf clicked set [pause v] to [-1] wait until <key [space v] pressed?> set [pause v] to [1] forever if <key [space v] pressed?> set [pause v] to ((-1)*(pause)) end
when key [left arrow v] pressed if <(pause)=[1]> do game end when key [right arrow v] pressed if <(pause)=[1]> do more stuff end
Last edited by 30-1 (2012-11-13 09:43:48)
Offline