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

#1 2012-08-22 07:24:48

FishingPro98
Scratcher
Registered: 2012-06-18
Posts: 35

How to make a button work only once?

Hi I'm making a project and to progress to the next screen you press 'g',but if you press 'g'
again after that its mucks up the whole thing so how do you make the 'g' button only work that once?

Please help!Really grateful  smile


Comment, Love, Play.

Offline

 

#2 2012-08-22 07:46:11

Hotwire
Scratcher
Registered: 2011-08-10
Posts: 500+

Re: How to make a button work only once?

FishingPro98 wrote:

Hi I'm making a project and to progress to the next screen you press 'g',but if you press 'g'
again after that its mucks up the whole thing so how do you make the 'g' button only work that once?

Please help!Really grateful  smile

Make a variable called 'g'. Then when the green flag is clicked make 'g' set to 'not pressed'.
Now when G is pressed set 'g' to 'pressed'
However put whatever action you want in an 'if else' statement of
[<if <not<g = not pressed>>]
[progress to next slide]
[else]
[leave the bit blank.]


http://i47.tinypic.com/293wn60.png

Offline

 

#3 2012-08-22 07:47:58

benjamin2
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: How to make a button work only once?

when green flag clicked
set [g pressed v] to (0)
wait (0) secs
wait until <key [g v] pressed?>
set [g pressed v] to (1)

when green flag clicked
wait (0) secs
wait until <key [g v] pressed?>
do stuff
Darn, outposted.  sad

Last edited by benjamin2 (2012-08-22 07:48:09)


http://i.imgur.com/gp6tZ.gif

Offline

 

#4 2012-08-22 09:24:12

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

Re: How to make a button work only once?

yes, the wait until block would work for this.


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

 

#5 2012-08-23 20:11:35

Scratcher456
Scratcher
Registered: 2010-12-04
Posts: 58

Re: How to make a button work only once?

How about

when gf clicked
set [g] to (0)
forever
     if <<key [g v] pressed> and <(g)=[0]>>
          set [g v] to (1)
     end
end
Sorry about the messed up block

Last edited by Scratcher456 (2012-08-23 20:13:22)


Mining diamonds, mining diamonds, mining diamonds...

Offline

 

#6 2012-08-23 20:33:34

gfchll
Scratcher
Registered: 2012-04-21
Posts: 100+

Re: How to make a button work only once?

when key [g v] pressed
do script
stop script

Last edited by gfchll (2012-08-23 20:33:58)


HELLO EVERYBODY!

Offline

 

#7 2012-08-23 20:33:39

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make a button work only once?

Scratcher456 wrote:

How about

when gf clicked
set [g v] to (0)
forever
     if <<key [g v] pressed?> and <(g)=[0]>>
          set [g v] to (1)
     end
Sorry about the messed up block

Fixed!


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-08-23 20:36:26

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make a button work only once?

gfchll wrote:

when key [g v] pressed
do script
stop script

That wouldn't work. I was thinking more along he lines of:

when gf clicked
your script
repeat until (key [g v] pressed?)
 your scripts
end
your scripts

Last edited by ErnieParke (2012-08-23 20:37:12)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer