Discuss Scratch

-Arachnid-
Scratcher
100+ posts

"If List Contains"

My Suggestion: A Block that searched an entire list for a letter.
I was recently working on a project that required a sprite to pick out certain words from a list that had letters placed in it by the user. I dedicated an entire sprite to the task, but then realized I would most likely need one sprite per word.
I was using a script that involved checking every space in the list for a letter that started off the word.
But if there was a block that searched the ENTIRE list for a single letter, I could do this with probably thirty blocks. Alas, there isn't, and now my script will forever be humongous.
Is there a workaround to this? If so, please inform me.
powercon5
Scratcher
1000+ posts

"If List Contains"

Wait, What is it you want to do?

Not this
containsthing?
?
-Arachnid-
Scratcher
100+ posts

"If List Contains"

powercon5 wrote:

Wait, What is it you want to do?

Not this
containsthing?
?
Lol.
I looked over the only block that I actuallly needed.
powercon5
Scratcher
1000+ posts

"If List Contains"

-Arachnid- wrote:

powercon5 wrote:

Wait, What is it you want to do?

Not this
containsthing?
?
Lol.
I looked over the only block that I actuallly needed.
So that is what you need?
LionHeart70
Scratcher
1000+ posts

"If List Contains"

containsletterof?
Or am I missing something?
FancyFoxy
Scratcher
500+ posts

"If List Contains"

LionHeart70 wrote:

containsletterof?
Or am I missing something?
No, I don't think that will work. It'll just see if anything in the list is the same thing as letter X of Y.
LionHeart70
Scratcher
1000+ posts

"If List Contains"

FancyFoxy wrote:

LionHeart70 wrote:

containsletterof?
Or am I missing something?
No, I don't think that will work. It'll just see if anything in the list is the same thing as letter X of Y.
Hmm.. well, I am still pretty new to lists, so..
andyhanwu
Scratcher
76 posts

"If List Contains"

I'm a lists expert and I think that what you need is nested loops to check each letter of every list item.
https://scratch.mit.edu/projects/168851013/#editor
Auroura_Wolf
Scratcher
1000+ posts

"If List Contains"

setfooto0setfoo2to0repeatlengthofitemfoovoflistifletterfoo2ofitemfoovoflist]={letter name here} then. . .else...:greychangefoo2by1changefooby1end
Something like that should do it, I gotta go so I can't finish writing the script, it's missing a repeat somewhere though

Last edited by Auroura_Wolf (July 14, 2017 13:51:38)

FancyFoxy
Scratcher
500+ posts

"If List Contains"

Auroura_Wolf wrote:

setfooto0setfoo2to0repeatlengthofitemfoovoflistifletterfoo2ofitemfoovoflist]={letter name here} then. . .else...:greychangefoo2by1changefooby1end
Something like that should do it, I gotta go so I can't finish writing the script, it's missing a repeat somewhere though
This script takes up time to run. The block is supposed to return a value in an instant, like the
containsthing?
block.
Sheep_maker
Scratcher
1000+ posts

"If List Contains"

FancyFoxy wrote:

Auroura_Wolf wrote:

. . .
Something like that should do it, I gotta go so I can't finish writing the script, it's missing a repeat somewhere though
This script takes up time to run. The block is supposed to return a value in an instant, like the
containsthing?
block.
Then put it in a custom block running without screen refresh:
definelistcontainsstr...strsetresultto...listcontains... in use...result
FancyFoxy
Scratcher
500+ posts

"If List Contains"

Sheep_maker wrote:

FancyFoxy wrote:

Auroura_Wolf wrote:

. . .
Something like that should do it, I gotta go so I can't finish writing the script, it's missing a repeat somewhere though
This script takes up time to run. The block is supposed to return a value in an instant, like the
containsthing?
block.
Then put it in a custom block running without screen refresh:
definelistcontainsstr...strsetresultto...listcontains... in use...result
Once again, I forget Run Without Screen Refresh is a thing. Whoops.
sfbs32175
New Scratcher
1 post

"If List Contains"

powercon5 wrote:

-Arachnid- wrote:

powercon5 wrote:

Wait, What is it you want to do?

Not this
containsthing?
?
Lol.
I looked over the only block that I actuallly needed.
So that is what you need?

I tried using that block but it actually didn't do anything.
I did:

If <___ contains answer>
say “hello”

but it doesn't do anything.
Is it because I'm using the answer block?
StrangeMagic32
Scratcher
1000+ posts

"If List Contains"

sfbs32175 wrote:

I tried using that block but it actually didn't do anything.
I did:

If <___ contains answer>
say “hello”

but it doesn't do anything.
Is it because I'm using the answer block?
I would suggest making a new topic in Help with scripts. That way you are more likely to get help.

Last edited by StrangeMagic32 (Oct. 22, 2018 13:13:19)

space_elephant
Scratcher
500+ posts

"If List Contains"

with custom reporters
definelistcontainssubstring?clearcounterrepeatlengthoflistincrementcounterifitemcounteroflistcontainssubstring?returnnotreturn
tlochsta
Scratcher
3 posts

"If List Contains"

huh
dave-alt-4
Scratcher
1000+ posts

"If List Contains"

pls dont necropost (note : topic is resolved(#3))
WescomProgramming
Scratcher
1 post

"If List Contains"

containsthing?
is used to check if a list contains something. Here's how to use it :

Detect if a list contains something
saylistcontainsthing?for2secs

Detect if a list contains multiple things
To use this script, the first thing you need is to create a variable, and another list with the same contents as the targeted list.
setread variableto1repeatuntilreadvariable>lengthofanother listiflistcontainsitemreadvariablevofanother list?thensaylistcontainsitemreadvariablevofanother list?for2secschangeread variableby1

Note : You can use anything to display the output.

Last edited by WescomProgramming (July 26, 2022 09:24:38)

Powered by DjangoBB