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

#1 2007-09-20 22:47:57

Nosh
Scratcher
Registered: 2007-08-31
Posts: 3

Help with Random-Letter-Button

I'm working on a game in which a random letter is supposed to show up on the background.  The player is then supposed to press that letter key.  Upon pressing the key the letter is supposed to disappear, and be replaced by another random letter.  This cycle has to continue until time runs out.  Right  now I'm using a separate sprite for each letter, and  a random broadcast that sends a number (1-26) that corresponds to a letter. The problem is that I can't get the letters to disappear after the key is pressed, so they just pile up on top of each other. I realize that I might not be entirely clear on this, but I would really appreciate any advice.


Bill the Game
Coming Soon!
Tell all your friends!

Offline

 

#2 2007-09-21 12:02:02

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: Help with Random-Letter-Button

how about one sprite with 26 costumes. 
start the entire thing with a broadcast called next letter.  (this can be triggered by the green flag)
you have a variable called 'letter' which you set to a random number from 1-26.  then set costume to 'letter' (the variable)
then show
then the only solution i can think of at the moment is a list of ifs like this:
if letter=1 wait until key 'A' pressed,
hide
broadcast 'next letter'
if letter=2 wait until key 'B' pressed
hide
broadcast 'next letter'
etc
this starts the entire routine again.

im not sure if this is the best way but you may wish to try.  i hope i have written it clearly enough.
goodluck


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#3 2007-09-21 22:44:02

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Help with Random-Letter-Button

I agree with the notion of one sprite with multiple costumes.
I think that the responsive behavior is probably best done with 26 short scripts that look something like this:

when key 'a' clicked
   if letter = 1
      broadcast new-letter

One script can handle all the stuff for producing new letters (and keeping track of scores if you want):

when new-letter received
    set letter to random 1 to 26
    set costume to letter

Offline

 

#4 2007-09-24 16:35:19

Nosh
Scratcher
Registered: 2007-08-31
Posts: 3

Re: Help with Random-Letter-Button

Those ideas helped, and I think I'm on the right track, but there are still some major problems.
I'm confused by this part:
[blocks]<switch to costume[  <{ letter }> [/blocks]
How does it know which costume "letter" is corresponding to?
I can't get the costume to change after the correct letter is pressed, and I'm guessing that this is to blame.


Bill the Game
Coming Soon!
Tell all your friends!

Offline

 

#5 2007-09-24 16:47:15

Mick
Scratcher
Registered: 2007-03-23
Posts: 100+

Re: Help with Random-Letter-Button

Set the variable 'letter' to random 1 - 26 every time you want a new letter to come up.
e.g.:

<when I receive[ next letter
<set{ letter }to( <pick random( 1 )to( 26
<switch to costume[ <{ letter }>


Go to www.legoless.com
It's my blog.  big_smile

Offline

 

#6 2007-09-24 16:48:39

Mick
Scratcher
Registered: 2007-03-23
Posts: 100+

Re: Help with Random-Letter-Button

Man, I LOVE these script images! They make explanining something soo much easier!


Go to www.legoless.com
It's my blog.  big_smile

Offline

 

#7 2007-09-27 15:44:29

Nosh
Scratcher
Registered: 2007-08-31
Posts: 3

Re: Help with Random-Letter-Button

Mick wrote:

Man, I LOVE these script images! They make explanining something soo much easier!

Congratulations, but there was really no need to post that separately.

Anyway, I'm still having trouble with my game. I'm getting really close though!
My current problem is that when I start the game, a letter will show up, but then it doesn't correspond to the correct key on the keyboard.  The only way to tell which key to press is to go to the scripts and see which script is illuminated.  Then, when you push the button it indicates (which is not the one on the screen), the letter on the screen changes to another one (good!), but then no key will work for it (bad!). 
Any help on any of these issues will be appreciated.


Bill the Game
Coming Soon!
Tell all your friends!

Offline

 

Board footer