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

#1 2011-03-17 19:42:32

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Checking if an answer is a number

Is it possible to check if an answer of a question is equal to a number? I am making a drawing game where you get to choose the color of the pen. Please help! I would really appreciate it! Thanks!

Offline

 

#2 2011-03-17 20:04:35

mrkeg101
Scratcher
Registered: 2010-11-20
Posts: 91

Re: Checking if an answer is a number

I can help.


<when green flag clicked>
<broadcast[ mrkeg101

Offline

 

#3 2011-03-17 20:10:17

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Checking if an answer is a number

Use:
If answer*1=answer

When this is true, it's a number.  When it's false, it used letters or something other than numbers.


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#4 2011-03-17 20:10:17

lemonpretzel
Scratcher
Registered: 2008-10-23
Posts: 100+

Re: Checking if an answer is a number

Do this:
If { [ not (answer) = 0 ] and [ (answer/1) = 0 ] }
Then answer if a letter.
Else
Answer is a number.

Offline

 

#5 2011-03-17 20:11:47

lemonpretzel
Scratcher
Registered: 2008-10-23
Posts: 100+

Re: Checking if an answer is a number

Kileymeister wrote:

Use:
If answer*1=answer

When this is true, it's a number.  When it's false, it used letters or something other than numbers.

lemonpretzel wrote:

Do this:
If { [ not (answer) = 0 ] and [ (answer/1) = 0 ] }
Then answer if a letter.
Else
Answer is a number.

Wow, we posted at the exact same time! 20:10:17

Offline

 

#6 2011-03-17 20:14:52

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Checking if an answer is a number

lemonpretzel wrote:

Kileymeister wrote:

Use:
If answer*1=answer

When this is true, it's a number.  When it's false, it used letters or something other than numbers.

lemonpretzel wrote:

Do this:
If { [ not (answer) = 0 ] and [ (answer/1) = 0 ] }
Then answer if a letter.
Else
Answer is a number.

Wow, we posted at the exact same time! 20:10:17

Holy cow.  And we both had similar answers that both work.
Haha, I win by a second or something though.  tongue

Last edited by Kileymeister (2011-03-17 20:15:04)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#7 2011-03-18 00:36:09

alex30003
New Scratcher
Registered: 2011-03-18
Posts: 1

Re: Checking if an answer is a number

lemonpretzel wrote:

Do this:
If { [ not (answer) = 0 ] and [ (answer/1) = 0 ] }
Then answer if a letter.
Else
Answer is a number.

Thank you ...  smile

Offline

 

#8 2011-03-18 16:46:23

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Checking if an answer is a number

Thanks guys!

Offline

 

#9 2011-03-18 16:59:13

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Checking if an answer is a number

Aww, it didn't work. sad  Also for yours lemon pretzel it just needs a letter in it.

Offline

 

#10 2011-03-18 17:05:30

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Checking if an answer is a number

I mean number. Also kileymeister's works but I am trying to make it change the pen color and that won't work. sad

Offline

 

#11 2011-03-19 05:32:47

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Checking if an answer is a number

lemonpreztel's looks dodgy, especially knowing that scratch looks at the last boolean in an AND block to see if it's true...

Offline

 

#12 2011-03-19 08:47:22

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Checking if an answer is a number

ImagineIt wrote:

I mean number. Also kileymeister's works but I am trying to make it change the pen color and that won't work. sad

"Set pen color to answer" won't work?  Are you sure it's the correct sprite that's changing its pen color?


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#13 2011-03-19 09:33:32

YourLocalBlockLib
Scratcher
Registered: 2011-03-10
Posts: 100+

Re: Checking if an answer is a number

I use:
[blocks]
<if> << <( (( answer <-> 0 )) <=> 0 )> <and><<  <not> <( answer <=> 0 )> >> >>
<set{ letter or number }to( letter
<else>
<set{ letter or number }to( number

[/blocks]
~Pecola1

Last edited by YourLocalBlockLib (2011-03-19 09:34:12)


http://dl.dropbox.com/u/6273449/BlockLibraryTitle.png

Offline

 

#14 2011-03-19 13:54:58

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

Re: Checking if an answer is a number

I use this:

<< <( <{ x }> <>> 0 )> <or> << <( x <<> 0 )> <or> <( <{ x }> <=> 0 )> >> >>


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

Offline

 

Board footer