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

#1 2011-12-18 22:12:39

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

want to run different scripts for each key pressed -having problems

Hi.  I shared a program called Hieroglyphs Rock 1.0 where I have a different script to run for each letter of the alphabet pressed.  The problem is, when more than one letter is pressed at a time, the scripts run simultaneously and everything gets messed up.  I can't figure out how to get the sound, talk bubbles, and movements from one letter's script to stop when another letter is pressed.  Thanks in advance for any help you can give me.

Offline

 

#2 2011-12-18 22:18:45

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

You need a heiarchy. In the block for "a" put "if not key b pressed or not key c pressed or not key d pressed" etc..

Then for "b" you would put "if not key c pressed or not key d pressed" etc..

And so on.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#3 2011-12-18 22:28:15

PaperMario123
Scratcher
Registered: 2011-11-25
Posts: 500+

Re: want to run different scripts for each key pressed -having problems

There's a quicker way...

First, make it so, when the Green Flag is clicked, it sets "variable" to 0.
Then, just do the "When [] key pressed" hat block, then an "if <variable=1>" block, and, whenever a key is pressed, it sets variable to 1, and when the key isn't pressed, it sets it to 0.


http://i.picasion.com/pic46/52268c4a041cced4c8ed97cc7468f869.gif

Offline

 

#4 2011-12-19 10:18:31

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

PaperMario123 wrote:

There's a quicker way...

First, make it so, when the Green Flag is clicked, it sets "variable" to 0.
Then, just do the "When [] key pressed" hat block, then an "if <variable=1>" block, and, whenever a key is pressed, it sets variable to 1, and when the key isn't pressed, it sets it to 0.

Really? I find my way to be a lot less time consuming.

I just duplicate the “ifs”.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#5 2011-12-19 11:03:27

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

thanks so much 4 the help!!!   big_smile

Offline

 

#6 2011-12-19 11:04:31

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

Did it work?


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#7 2011-12-19 11:17:58

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

hey guys i'm a new scratcher and a very visual person. could you please show me an example thank so much!!!!!!

Offline

 

#8 2011-12-19 12:28:30

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

Yes, I'll quickly make a script for you right now:
http://img28.imageshack.us/img28/2914/keyexample.gif

That way, it won't collide, and you just repeat that script down until Z or however many letters you want.


Hai.

Offline

 

#9 2011-12-19 13:27:45

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

hey, i tried what fg123 said, and it stopped me from pressing a letter while the other one is running. this is good, but could anyone possibly think of a way to have it switch to the other one and stop the first letter while it's running??? thanks so much 4 any help!!!!  smile

Offline

 

#10 2011-12-19 13:40:36

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

When a topic is resolved, click the report button and type “Topic Resolved” then a moderator will come and close it.

For instance, I’m going to report it now, and then a moderator or Scratch Team member will be here.

Watch:


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#11 2011-12-19 14:14:12

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

henley wrote:

When a topic is resolved, click the report button and type “Topic Resolved” then a moderator will come and close it.

For instance, I’m going to report it now, and then a moderator or Scratch Team member will be here.

Watch:

Thanks for the advice...but moderators usually wait to hear from the topic owner before they close the topic.  Besides, from the last post by the owner,  it sounds like there are still some issues to be resolved  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#12 2011-12-19 14:24:46

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

iheartpeek-a-boo wrote:

hey, i tried what fg123 said, and it stopped me from pressing a letter while the other one is running. this is good, but could anyone possibly think of a way to have it switch to the other one and stop the first letter while it's running??? thanks so much 4 any help!!!!  smile

Hmm, that could be complicated. Try:
http://img221.imageshack.us/img221/2298/keyexampl2.gif

Again, repeat as needed.


Hai.

Offline

 

#13 2011-12-20 15:52:53

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

fg123, it didn't work. it didn't let me press the other letter, just like last time. any other ideas???? i have to fix this!!!!!  yikes  again, thanks 4 the help.

Offline

 

#14 2011-12-20 17:47:45

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

iheartpeek-a-boo wrote:

fg123, it didn't work. it didn't let me press the other letter, just like last time. any other ideas???? i have to fix this!!!!!  yikes  again, thanks 4 the help.

Really? It worked for mee...

So what you want is:

I press "a", "a" stuff happens.
If I keep holding "a" and press "b", "b" stuff happens.
If I keep holding "a", "b" and press "c", "c" stuff happens.


Is that you want?


Hai.

Offline

 

#15 2011-12-20 18:26:06

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

I delt with this type of issue when writing my Hangman game.

I made a list variable for holding all the keystrokes that have been pressed.

You can see it here: http://scratch.mit.edu/projects/BoltBait/463279

Hope this helps.

Last edited by BoltBait (2011-12-20 18:26:47)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#16 2011-12-20 20:57:50

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

dear fg123,

nope. not working. would u share yours? maybe something's wrong. or maybe i've messed up. that's probably more likely.

Offline

 

#17 2011-12-20 21:46:39

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

Hello again.  I'm going to try to be more clear about what I'm trying to do.  I so appreciate everybody's help!

This is what I'd like my programming to do:
I press "a", "a" stuff happens,
I press "b" (or k or x or whatever), "a" stuff STOPS happening and "b" stuff happens (or k stuff or x stuff or whatever letter's stuff you pushed)
I'm not trying to hold down any keys while pushing others.  I just want to push one letter at a time and I want the scripts for the previous letter to STOP (even if they aren't finished running) when I push a different letter.

Thanks again!

Offline

 

#18 2011-12-20 22:53:40

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: want to run different scripts for each key pressed -having problems

Oh, well let me change my script a little. If in the case of holding, it takes the second button's action, right?


Hai.

Offline

 

#19 2011-12-21 00:18:52

iheartpeek-a-boo
Scratcher
Registered: 2011-12-15
Posts: 12

Re: want to run different scripts for each key pressed -having problems

fg123 wrote:

Oh, well let me change my script a little. If in the case of holding, it takes the second button's action, right?

I don't have any programming right now that calls for holding down buttons.  It works fine if one letter is pushed at a time and you wait for the scripts to run their course before you push the next letter.  But my users who tested the program wanted to be able to "change their mind."  For example, after pushing the "f" key, they wanted to be able to push the "o" key to see what it would do without waiting for the "f" key scripts to finish what they were doing.  The way my program is now, if you push the "f" and then a few seconds later, push the "o", you will hear/see everything for both letters simultaneously.

Wow, I sure appreciate you spending time helping me solve this problem!

Offline

 

Board footer