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

#1 2008-12-29 13:09:42

i_caught_fire_2
Scratcher
Registered: 2008-12-23
Posts: 20

Help needed! Please!

In the game I'm making, when you hit the 'o' key, a bunch of obstacles go by continuously.
How do i get it so that when I hit the 'o' key again, it will stop that script?

Offline

 

#2 2008-12-29 13:30:31

horselover
Scratcher
Registered: 2008-01-26
Posts: 96

Re: Help needed! Please!

I don't think you can. You would probably have to use a different letter to make the script stop.


Scratch is so cool!

Offline

 

#3 2008-12-29 13:33:57

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Help needed! Please!

i_caught_fire_2 wrote:

In the game I'm making, when you hit the 'o' key, a bunch of obstacles go by continuously.
How do i get it so that when I hit the 'o' key again, it will stop that script?

You could create a variable called Stop/Start. The first time you press "O" you could say
<when green flag clicked>
<forever>
<if> <key[ o ]pressed?>
<if><( <{ S/S }> <=> 1 )>
<set{ S/S }to( 2
<else>
<if><( <{ S/S }> <=> 2 )>
<set{ S/S }to( 1

<when green flag clicked>
<forever>
<if> <( <{ S/S }> <=> 2 )>
<stop script>

Offline

 

#4 2008-12-29 16:58:33

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

Re: Help needed! Please!

If you want the script to sop forever when you press O, this is what I'd do:
<when green flag clicked>
<wait until><key[ O ]pressed?>
<wait until><not> <key[ O ]pressed?> >>
<forever>
  [your movement scripts here]
  <if><key[ O ]pressed?>
    <stop script>
  <end>
<end>

[/blocks]If you want to make it so that you can toggle it from moving to not moving, make a variable called moving. Then make these 2 scripts:
[blocks]<when green flag clicked>
<set{ moving }to( 0
<forever>
  <if><key[ O ]pressed?>
    <if><( <{ moving }> <=> 0 )>
      <set{ moving }to( 1
    <else>
      <set{ moving }to( 0
    <end>
  <wait until><not> <key[ O ]pressed?> >>
<end>

<when green flag clicked>
<forever>
  <if><( <{ moving }> <=> 1 )>
    [your movement scripts here]
  <end>
<end>
[/blocks]

Last edited by hmnwilson (2008-12-30 01:38:20)


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 2008-12-30 00:07:33

i_caught_fire_2
Scratcher
Registered: 2008-12-23
Posts: 20

Re: Help needed! Please!

Thanks but niether worked for me and i copied them perfectly.
Any other suggestions??

Offline

 

#6 2008-12-30 00:49:35

i_caught_fire_2
Scratcher
Registered: 2008-12-23
Posts: 20

Re: Help needed! Please!

The stop forever worked but Id rather not have that.

Offline

 

#7 2008-12-30 01:28:31

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

Re: Help needed! Please!

So the toggling one doesn't work? OK, let me test my script out, just wait. I'll edit this post when I'm done.

Edited: I don't know why it didn't work for you, but I posted a project with a working script. http://scratch.mit.edu/projects/hmnwilson/365856

Last edited by hmnwilson (2008-12-30 01:41:35)


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

 

#8 2008-12-30 08:02:08

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Help needed! Please!

<when green flag clicked>
<wait until><key[ o ]pressed?>
<broadcast[ start obstacles
<wait until><not> <key[ o ]pressed?> >>
<wait until><key[ o ]pressed?>
<stop all>

Offline

 

#9 2008-12-30 13:22:30

i_caught_fire_2
Scratcher
Registered: 2008-12-23
Posts: 20

Re: Help needed! Please!

okay it works now.
Thank ya'll!

Offline

 

Board footer