How do I make script know multiple items from list instead of just 1?

id: 750018

category: Help with Scripts

posts: 13

Jackmode368 Jackmode368 loading
Helo! So you know the
(item ( v) of [list v] :: list)
block? That only allows for you to pick one item from list. How do I make it pick multiple or all?
For example, let's say I want to detect if the item a player has any of these items from a list, how do I make it detect that without using a bunch of or blocks? Like this:

[
if <(Items) = (item (1, 3, 5, 6, or 13 v) of [list v] :: list)> then
say [Congratulations!] for (2) secs

end

cause sometimes there are a lot of items and I'm not putting 56 or blocks in a single line.




Malicondi Malicondi loading
A couple ways to go about this, you could use this block:
<[list v] contains ()?>
But if there are other items you don't want it to be, you could make a seperate list and check if the item is inside of the seperate list. I will do some testing, and see if I can make a simple custom block to check multiple items, as I can't make one from memory without testing.
Jackmode368 Jackmode368 loading
Well, seeing if the list has something from the list won't do much, and either way, you can still only select one option.
Malicondi Malicondi loading

Jackmode368 wrote:

Well, seeing if the list has something from the list won't do much, and either way, you can still only select one option.
Using the
<[list v] contains ()?>
block is one argument for a reason. Say you have a list of these items:
1
6
2
7
4
And if you use the block, like this:
<[list v] contains (4)?> 
it will return true because of all the items, it has it. If you only want a select few items, you can add them to a seperate list and use the list contains block, as it is the simplest option. I did make a custom blocks to check any amount of a specific item of a list, say you want to check items 1 7 9, then you can use this custom blocks to check those items:
define is thing (t) in items (i) of list?
set [letter v] to (0)
set [i v] to (1)
repeat until <(letter) = ()> // leave blank
set [item v] to () // blank
set [letter v] to (0)
repeat until <<(letter) = ()> or <(letter) = [,]>> // one of these must be a comma.
set [letter v] to (letter (i) of (t))
change [i v] by (1)
set [item v] to (join (item) (letter))
end
if <(t) = (item (item) of [example list v])> then
say [This item is in the list!]
stop [this script v]
end
end
say [This item is not in the list.]
You can use this block to check multiple items like this:
is thing [hello] in items [1,6,9,2] of list? ::custom
I wasn't able to come up with a simpler design to take any amount of items, but the order of numbers doesn't matter, and you can check as many items as you'd like. Hope this helps!
Jackmode368 Jackmode368 loading
That lags out my scratch, sorry.

To be clear, let's say a player types in “A B C D E F G” in the answer box. If answer contains list item 3, or 5, or 4, or 8, or 10 etc., do action. Yet I'd need a bunch of these
<<> or <>>


Example:

if <<(answer)> contains <(item (3 v) of [list v] :: list) or <(item (5 v) of [list v] :: list) or <(item (4 v) of [list v] :: list) or <(item (8 v) of [list v] :: list) or (item (10 v) of [list v] :: list)>>>>> then

end

which obviously gets really inconvenient, especially when it's a large amount of things.
So I need something that can act as a
(item (3, 5, 4, 8, 10 v) of [list v] :: list)

Thank you!
set [i v] to [1]
repeat (length of [list v] :: list)
if <[(answer) v] contains (item (i) of [list v] :: list) ?> then
output true somehow (could set a var or maybe broadcast a message)
stop [this script v]
end
change [i v] by (1)
end
output false somehow (could set a var or maybe broadcast a message)
or

set [i v] to [1]
repeat until <<(i) > (length of [list v] :: list))> or <[(answer) v] contains (item (i) of [list v] :: list) ?>>
change [i v] by (1)
end
if <[(answer) v] contains (item (i) of [list v] :: list) ?> then
output true
else
output false
end
either will work. The top is most useful in a custom block. Also the “contains” block should be green and can be found in the operations section in 3.0.
Jackmode368 Jackmode368 loading
the contains block doesn't show in the forums for some reason
Jackmode368 Jackmode368 loading
What block is the (i)v)

Jackmode368 wrote:

What block is the (i)v)

oh mb it should be the variable I
(i)
I fixed the original post so It should work now.
Put the numbers in a seperate list and compare item 1, 2, 3… with an idx variable (i.e. check 1, then change idx to 2, check item 2, etc.)
lgrov44 lgrov44 loading

Jackmode368 wrote:

That lags out my scratch, sorry.

To be clear, let's say a player types in “A B C D E F G” in the answer box. If answer contains list item 3, or 5, or 4, or 8, or 10 etc., do action. Yet I'd need a bunch of these
<<> or <>>


Example:

if <<(answer)> contains <(item (3 v) of [list v] :: list) or <(item (5 v) of [list v] :: list) or <(item (4 v) of [list v] :: list) or <(item (8 v) of [list v] :: list) or (item (10 v) of [list v] :: list)>>>>> then

end

which obviously gets really inconvenient, especially when it's a large amount of things.
So I need something that can act as a
(item (3, 5, 4, 8, 10 v) of [list v] :: list)

Thank you!
How's this?
Temp - List of the numbers for the numbered items to check.
Temp2 - The list searched in
Temp3 - What is searched for in those checked number items
Temp4 - The answer

set [i v] to [1]
set [Temp4 v] to [False]
repeat (length of [Temp2 v] :: list)
if <<[Temp2 v] contains (Temp3) ?> and <[Temp v] contains (i) ?>> then
set [Temp4 v] to [True]
end
end

This is the answer for whether a group of specific items in a list contains a specific string of text which is what I assume is what you are asking for.


If you are asking for the answer to be some defined group of items in that list expressed as a string of text, try this:
Temp - List of the numbers for the numbered items to check.
Temp2 - The list searched in
Temp3 - The response

set [Temp3 v] to []
set [i v] to []
repeat (length of [Temp2 v] :: list)
change [i v] by (1)
if <[Temp v] contains (i) ?> then
set [Temp3 v] to (join (Temp3) (join [, ] (item (i) of [Temp2 v] :: list)))
end
end
set [i v] to []
repeat (length of [Temp3])
change [i v] by (1)
add (letter (i) of (i)) to [i v]
end
delete (1 v) of [i v]
set [Temp3 v] to []
repeat (length of [i v] :: list)
set [Temp3 v] to (item (1 v) of [i v] :: list)
delete (1 v) of [i v]
end
Jackmode368 Jackmode368 loading
Thank you, Igrov! How do you make temp3 equal multiple seperate numbers, though?
without a bunch of
<<> and <>>
lgrov44 lgrov44 loading

Jackmode368 wrote:

Thank you, Igrov! How do you make temp3 equal multiple seperate numbers, though?
without a bunch of
<<> and <>>
Temp3 equal to multiple separate numbers? Are you referring to the first mentioned script? If so, try this:
Temp - List of the numbers for the numbered items to check.
Temp2 - The list searched in
Temp3 - What is searched for in those checked number items as a list
Temp4 - The answer
set [m v] to []
repeat (length of [Temp3 v] :: list)
change [m v] by (1)
set [i v] to [1]
set [Temp4 v] to [False]
repeat (length of [Temp2 v] :: list)
if <<[Temp2 v] contains (item (m) of [Temp3 v] :: list) ?> and <[Temp v] contains (i) ?>> then
set [Temp4 v] to [True]
end
end
end

I don't know how you would do it if you are referring to the other script, only because I would not know what it would mean to do that with the assumption that I have not alrighty done that. If I knew, I could definitely help you with that.