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
I don't think you can. You would probably have to use a different letter to make the script stop.
Offline
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
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)
Offline
Thanks but niether worked for me and i copied them perfectly.
Any other suggestions??
Offline
The stop forever worked but Id rather not have that.
Offline
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)
Offline
<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
okay it works now.
Thank ya'll!
Offline