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

#1 2008-11-02 16:44:12

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

If a section of a list...

How do I say if a section of a list is a letter, and not a number?


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#2 2008-11-03 03:11:51

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: If a section of a list...

if it's a string it will evaluate to zero. So you could allow storing any number except zero and then test if (item n of list = 0).


Jens Mönig

Offline

 

#3 2008-11-03 07:32:33

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: If a section of a list...

So a bulletproof solution allowing zeros would be "item=0 and item+1=0"?
It supposes that addition appends the second operand when the first is string.

Offline

 

#4 2008-11-03 12:08:41

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Re: If a section of a list...

As said above, you can't really use letters as they will equal 0. However, when you are adding to the list, use numbers to represent the thing you are adding.

For example:

A = 1
B = 2


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

#5 2008-11-03 18:23:20

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: If a section of a list...

deerel wrote:

So a bulletproof solution allowing zeros would be "item=0 and item+1=0"?
It supposes that addition appends the second operand when the first is string.

Nice solution!


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#6 2008-11-04 18:02:36

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: If a section of a list...

fullmoon wrote:

deerel wrote:

So a bulletproof solution allowing zeros would be "item=0 and item+1=0"?
It supposes that addition appends the second operand when the first is string.

Nice solution!

I am one of those elegance-and-beauty-is-the-most-important-in-the-code freaks :-)

Last edited by deerel (2008-11-04 18:03:47)

Offline

 

Board footer