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

#1 2010-03-12 10:29:15

tezkalow
Scratcher
Registered: 2010-03-11
Posts: 5

Double Function Press

Perhaps this cannot be called as "double function". I want the first press to do something, and press that again to undo it, but how can i be done?
(Actually, I set the first press to set ghost effect(forever), the second press to cancel it)
Any suggestions would be appreciate. Thanks.

Offline

 

#2 2010-03-12 10:55:30

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Double Function Press

ok here's a simple way if it's ok to have it in it's own script:

<when[  ]clicked>
<set[ ghost ]effect to( 50
<wait until> <mouse down?>
<set[ ghost ]effect to( 0

(Otherwise you can have a variable that you check to see if it's on or not.)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#3 2010-03-16 03:42:50

tezkalow
Scratcher
Registered: 2010-03-11
Posts: 5

Re: Double Function Press

That's not mouse down!!
I want to press a key to active it's effect, and again to cancel.
Thanks any way.

Offline

 

#4 2010-03-16 14:33:40

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Double Function Press

tezkalow wrote:

That's not mouse down!!
I want to press a key to active it's effect, and again to cancel.
Thanks any way.

You can just replace <mouse down?>[/blocks] with <key[  ]pressed?>[/blocks] and it'll do the same thing.  smile


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#5 2010-03-16 16:19:02

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Double Function Press

This is called a "toggle". Example: an on/off switch.

I've always done it with a variable.

create a variable called "on"
set "on" to true (or 1)
When button pressed
if "on" is true (or 1)
set "on" to false (or 0)
else set "on" to true (or1)

Good luck! Remember to set your variable to false in the beginning.
When Flag clicked
set "on" to false

~Tony

     <{ on   }>


   <when green flag clicked>
   <set{   on     }to(   false
   <forever><if><key[  ]pressed?>
   <if>  <(  <{   on   }>  <=>  true    )>

DO OFF ACTION HERE, like "Turn Off The Lights"

   <set{  on  }to(  false     <-- Let the program know the lights are off
   <else>   (on is already false, the lights are already off)

DO ON ACTION HERE, like "Turn On The Lights"

   <set{  on  }to(  true     <-- Let the program know the lights are on

Last edited by infinitum3d (2010-03-16 16:29:30)

Offline

 

Board footer