Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » kinda wish scripts like these were in scratch.
- JockeySporta24
-
Scratcher
12 posts
kinda wish scripts like these were in scratch.
yall know the “() contains ()?” block? I wish they had a block that would let you put specific characters in a list in a variable, like for example
“if (List) contains (Username)” “set variable to: (Number of list character that has your username)”. And im talking about list characters with your username and something else attached to it. like..
1: “(Username)Hi”
If anyone knows what im talking about and has a script that works this way pls share.
“if (List) contains (Username)” “set variable to: (Number of list character that has your username)”. And im talking about list characters with your username and something else attached to it. like..
1: “(Username)Hi”
If anyone knows what im talking about and has a script that works this way pls share.
Last edited by JockeySporta24 (Dec. 31, 2022 05:54:26)
- MiniCoder11
-
Scratcher
100+ posts
kinda wish scripts like these were in scratch.
In order to search a list for any item containing a specific string, you can loop over each item of the list and check if it contains that string. If the item does contain the string, you can exit the loop and return the index, otherwise you can keep traversing the list until you find an item that contains the string. If you reach the end of the list before you find an item containing the string, you can set the index to 0 to indicate that the string does not exist in the list.
Here is an example implementation using a list named “list” for demonstration purposes:
Running this custom block will set the index variable to the index of the first item in the list that contains the inputted string or 0 if the string could not be found in any of the items in the list.
Here is an example implementation using a list named “list” for demonstration purposes:
define listSearch (string)
set [index v] to [1]
repeat until <<(item (index) of [list v]) contains (string)? :: operators> or <(index) > (length of [list v])>>
change [index v] by (1)
end
if <(index) > (length of [list v])> then
set [index v] to [0] // You can also set this to a different value to check for. The index will be set to this value if the string was not found in the list.
end
Running this custom block will set the index variable to the index of the first item in the list that contains the inputted string or 0 if the string could not be found in any of the items in the list.
- Discussion Forums
- » Help with Scripts
-
» kinda wish scripts like these were in scratch.




