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

#1 2012-04-09 17:20:14

yandro
New Scratcher
Registered: 2012-04-09
Posts: 3

different action pressing twice a button

I want to know how to perform an action pressing a button, but when i press it again i want to do the opposite action. For example, if i pressed x button, i want to equip a gun, but if i press it again, i want to quit it.


Can you help me with that? really i need it. Thanks!

Offline

 

#2 2012-04-09 17:28:46

pi3
Scratcher
Registered: 2011-12-31
Posts: 500+

Re: different action pressing twice a button

when gf clicked
set [gun equipped] to [0]
switch to costume [no gun]
forever
   wait until x key pressed
   switch to costume [gun]
   set [gun equipped] to [1]
   wait until <  not x key pressed >
   wait until x key pressed
   switch to costume [no gun]
   set [gun equipped] to [0]
   wait until < not x key pressed >
end
I think this should work.

Last edited by pi3 (2012-04-09 17:32:56)


http://i44.tinypic.com/ofdhc4.jpgThanks FreshStudios!

Offline

 

#3 2012-04-09 17:35:00

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: different action pressing twice a button

Or this:

When [space v] key pressed
change [i v] by (1)
if<((i) mod (2))=[0]>
show gun
else
hide gun
end
Or this:

When gf clicked
forever if<key [space v] pressed ?>
change [i v] by (1)
if<((i) mod (2))=[0]>
show gun
else
hide gun
end
end

Last edited by MoreGamesNow (2012-04-09 17:40:23)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2012-04-09 18:13:12

yandro
New Scratcher
Registered: 2012-04-09
Posts: 3

Re: different action pressing twice a button

More than thanks, but, i dont know how to aim that gun while having it, hehe. i want to shoot, reload when i have the gun. What i mean, is that i dont know how to make other actions with these scripts when i have the gun. When i quit it, those actions cannot be performed.

Thanks again!

Offline

 

#5 2012-04-09 18:24:25

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: different action pressing twice a button

Just only preform the actions when ( (i) mod [2]) = 0, like the code below.  Happy scripting  smile

when gf clicked
forever if <((i) mod [2]) = [0]>
point towards [mouse pointer v]
if<mouse down?>
broadcast [shoot v]
end
end

Last edited by MoreGamesNow (2012-04-09 18:25:38)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-04-09 18:25:43

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: different action pressing twice a button

MoreGamesNow wrote:

Just only preform the actions when ((i) mod [2]) = 0

when gf clicked
forever if <((i) mod [2]) = [0]>
point towards [mouse pointer v]
if<mouse down?>
broadcast [shoot v]
end
end

Blocks fixed by Coolhogs

Last edited by coolhogs (2012-04-09 18:26:58)


Get ready for domination of:  tongue

Offline

 

#7 2012-04-09 18:46:02

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: different action pressing twice a button

yandro wrote:

More than thanks, but, i dont know how to aim that gun while having it, hehe. i want to shoot, reload when i have the gun. What i mean, is that i dont know how to make other actions with these scripts when i have the gun. When i quit it, those actions cannot be performed.

Thanks again!

If I have you right, you could try my biiiig codes  tongue  I am a fan of big codes  big_smile

(Under the 'else' codes, move all of the 'if's' out of the other if's and keep them separate. Eg at the moment it goes
if this....
    if this......
         if this......

when it should be:

if this
OR
if this
OR
if this)

Hope it helps a bit.

when gf clicked
set [armed] to [0]
forever
switch to costume [armed]
if <(armed) = [0]>
       if [x] key pressed
                  set [armed] to [1]
                 wait until <not [x] key pressed>
else
point towards [mouse pointer]
        if <[x] key pressed>
                   set [armed] to 0
                    wait until <not [x] key pressed>
 if <[mouse down] and <[ammo] > 0>
                    broadcast fire
                   change [ammo] by [-1]
                    wait until <not mouse down>
if <[r] key pressed>
               set [ammo] to [10]


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#8 2012-04-09 20:47:20

yandro
New Scratcher
Registered: 2012-04-09
Posts: 3

Re: different action pressing twice a button

I ve manneged to equip and quit the gun. But i cant aim the gun cause of the other script. How can i make those variables to change the images having the gun to aiming? Im not doing an FPS, im not using a mouse. Im using images.

Offline

 

#9 2012-04-09 20:54:56

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: different action pressing twice a button

when gf clicked
forever
if <((i) mod [2]) = [0]>
show // gun is pointing towards
point towards [mouse pointer v]
if<mouse down?>
broadcast [shoot v]
end
else
hide // gun is away
end
end

When [space v] key pressed
change [i v] by [1]
That should take care of everything (I hope).

Last edited by MoreGamesNow (2012-04-09 20:55:45)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer