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

#1 2012-03-15 17:42:12

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Why does the (item (any v) of [listhere v]) pick a random thing?

Well, The title kind of says the story, but I was trying to make somthing where a list could have an infinite ammount of items and I didn't want to spend all of the time modifying my script to make it work with more and more items in the list, so I though any would've done it, but it only picks a random one out - What I was doing was this:

if <(item (any v) of [list v]) = (answer)>
 Obsolete, because i want to hide the rest of my code.
end

Last edited by DigiTechs (2012-03-15 17:43:31)


I'm back.
Maybe.

Offline

 

#2 2012-03-15 18:45:52

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

If you want to check all items of the list, use a loop:

set [counter v] to [1]
repeat (length of [list v])
    if <(item (counter) of [list v]) = (answer)>
        // do something
    end
    change [counter v] by [1]
end

Last edited by nXIII (2012-03-15 18:46:07)


nXIII

Offline

 

#3 2012-03-15 20:42:45

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

Any refers to 'any of them' which is random, and as nXII says there is a way to check any of the items.  smile


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#4 2012-03-16 12:31:54

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

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

wouldn't the boolean block

<[ x v] contains (answer)>
be more useful, in this case?

Last edited by LS97 (2012-03-16 12:33:38)

Offline

 

#5 2012-03-19 11:44:42

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

LS97 wrote:

wouldn't the boolean block

<[ x v] contains (answer)>
be more useful, in this case?

Doh. Why is my brain not working?


I'm back.
Maybe.

Offline

 

#6 2012-03-19 11:46:10

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

DigiTechs wrote:

LS97 wrote:

wouldn't the boolean block

<[ x v] contains (answer)>
be more useful, in this case?

Doh. Why is my brain not working?

Don't worry, many people forget that block exists.

Offline

 

#7 2012-03-19 11:58:31

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

That certainly is a useful block! It's only a shame there isn't a version that tells you what number it is stored it  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2012-03-19 14:11:18

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

Totally; it would be so useful and speed up your programs  tongue


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#9 2012-03-19 17:32:20

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

Although, I did find that costume names can be used as a list with a number return. Instead of "number of item [text] in [list]" you can do "switch to costume [text]" and then "costume #" will report the position.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2012-03-23 11:48:00

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

Well what I was doing was making an authentication system for somthing I was making, in BYOB, so i'll script most of what I was doing: (has been modified to what it is now)

if <( sentence - list (Userpasswords v sensor value) ) contains (answer)>
  etc..
end

Last edited by DigiTechs (2012-03-23 11:50:04)


I'm back.
Maybe.

Offline

 

#11 2012-03-23 11:50:54

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: Why does the (item (any v) of [listhere v]) pick a random thing?

DigiTechs wrote:

Well what I was doing was making an authentication system for somthing I was making, in BYOB, so i'll script most of what I was doing: (has been modified to what it is now)

if <( sentence - list ([Userpasswords v]sensor value) ) contains (answer)>
  etc..
end

Due to technical limitations, the sensorvalue block has failed to show.. unless (editing now, if you read the quotations, you're reading after i modified)


I'm back.
Maybe.

Offline

 

Board footer