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

#1 2011-02-16 01:18:29

Edlrargo
New Scratcher
Registered: 2011-02-11
Posts: 1

Rejecting Letters in Questions

Hi all,
I need help with a script whereby a sprite asks a question and the only logical answer is a numerical value. If a letter is entered, how can I reject it?

I've already tried creating a list with all the letters in it to no avail...

<if><( answer <=> letterlist  )>
<say[ wrong! ]for( 4  )secs>

Any ideas?  smile

Luke.

Offline

 

#2 2011-02-16 04:22:57

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

Re: Rejecting Letters in Questions

Take a look at the list block "contains"...it will do what you want.

if <letterlist Contains answer >
     Say Wrong! for 4 secs


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

Offline

 

#3 2011-02-16 20:15:45

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Rejecting Letters in Questions

Paddle's method will work great, but here's a little trick for figuring out if something isn't a number:

http://img155.imageshack.us/img155/8771/numberchecker.gif

How it works:
If you multiply a non-number by any number in Scratch, it will give you 0, so if you get 0 by multiplying the answer by 1 and that answer is not 0 itself, then you know the answer must be a non-number.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#4 2011-02-16 21:00:52

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

Re: Rejecting Letters in Questions

Nice method scmb1.  Lol, I was going to suggest breaking it apart letter by letter into a list and checking each individual item.  Yours is much better time-wise and efficiency-wise.


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

Offline

 

#5 2011-02-17 03:41:51

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Rejecting Letters in Questions

scmb1 wrote:

Paddle's method will work great, but here's a little trick for figuring out if something isn't a number:

http://img155.imageshack.us/img155/8771 … hecker.gif

How it works:
If you multiply a non-number by any number in Scratch, it will give you 0, so if you get 0 by multiplying the answer by 1 and that answer is not 0 itself, then you know the answer must be a non-number.

Was that from my project?

Offline

 

#6 2011-02-17 04:49:47

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: Rejecting Letters in Questions

scimonster wrote:

scmb1 wrote:

Paddle's method will work great, but here's a little trick for figuring out if something isn't a number:

http://img155.imageshack.us/img155/8771 … hecker.gif

How it works:
If you multiply a non-number by any number in Scratch, it will give you 0, so if you get 0 by multiplying the answer by 1 and that answer is not 0 itself, then you know the answer must be a non-number.

Was that from my project?

I guess not, because I think I've seen a script that's almost (or exactly) the same in a project before. I'm sure that's not your project because I think I have seen that project for a long time...

Offline

 

#7 2011-02-17 18:53:38

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Rejecting Letters in Questions

scimonster wrote:

scmb1 wrote:

Paddle's method will work great, but here's a little trick for figuring out if something isn't a number:

http://img155.imageshack.us/img155/8771 … hecker.gif

How it works:
If you multiply a non-number by any number in Scratch, it will give you 0, so if you get 0 by multiplying the answer by 1 and that answer is not 0 itself, then you know the answer must be a non-number.

Was that from my project?

No. Actually, I just thought of it myself. Gee, I thought I was being clever.  tongue


http://i48.tinypic.com/2z5pqad.png

Offline

 

#8 2011-02-18 09:04:27

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: Rejecting Letters in Questions

Then who should I give credit to if I want to use this method?

Offline

 

#9 2011-02-18 17:51:55

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Rejecting Letters in Questions

mathematics wrote:

Then who should I give credit to if I want to use this method?

I don't know who should technically get credit, but I don't care if I get credit for that little script, so give it to scimonster.


http://i48.tinypic.com/2z5pqad.png

Offline

 

Board footer