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

#1 2012-10-25 11:25:21

empathyart
New Scratcher
Registered: 2012-10-24
Posts: 8

Are you able to assign a button to do more than one thing?

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

 

#2 2012-10-25 11:32:15

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-10-25 12:07:41

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

#4 2012-10-25 13:37:54

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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]
end

fixed

thx


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#5 2012-10-25 14:41:41

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

Simpler way: (one that actually WORKS)

when key [space v] pressed
do something
when key [space v] pressed
do something different


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#6 2012-10-25 14:43:52

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#7 2012-10-26 11:18:58

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Are you able to assign a button to do more than one thing?

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

 

#8 2012-10-29 11:33:33

empathyart
New Scratcher
Registered: 2012-10-24
Posts: 8

Re: Are you able to assign a button to do more than one thing?

Thanks everyone!

Offline

 

#9 2012-10-29 11:36:10

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: Are you able to assign a button to do more than one thing?

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)


Alt of Firedrake969.

Offline

 

#10 2012-10-30 21:59:57

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: Are you able to assign a button to do more than one thing?

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]
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

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?


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=projects&amp;type=newest&amp;return=image&amp;num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=onlineStatus&amp;type=text

Offline

 

#11 2012-10-30 23:17:27

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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

 

#12 2012-11-06 15:14:59

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: Are you able to assign a button to do more than one thing?

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?


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=projects&amp;type=newest&amp;return=image&amp;num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=onlineStatus&amp;type=text

Offline

 

#13 2012-11-07 12:57:19

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Are you able to assign a button to do more than one thing?

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)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#14 2012-11-13 09:36:06

30-1
Scratcher
Registered: 2012-08-08
Posts: 100+

Re: Are you able to assign a button to do more than one thing?

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))
 end
And 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)


http://i.imgur.com/ocOya7x.gif
I. Text I Based I Games I

Offline

 

#15 2012-11-13 09:44:06

30-1
Scratcher
Registered: 2012-08-08
Posts: 100+

Re: Are you able to assign a button to do more than one thing?

Hopefully
The hopefully was meant to be in caps is this a bug or deliberate?

Last edited by 30-1 (2012-11-13 09:45:44)


http://i.imgur.com/ocOya7x.gif
I. Text I Based I Games I

Offline

 

Board footer