Item number of () in (): Difference between revisions
Item number of () in ()
Content deleted Content added
Created page with "{{Infobox Block |category = Lists |title = item # of () in () |block_name = item # of [] in [ v] |block_type = Reporter Block }} {{Incorrect Title|item # of () in ()}} The '''item # of () in ()''' block is a reporter block in the Lists category that reports the item number of the first occurrence of the inputted item in the selected list. It was introduced in Scratch 3.0. ==Workaround== This block can be worked around using the following code: <scratchblocks> def..." |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 6:
}}
{{Incorrect Title|item # of () in ()}}
The '''item # of () in ()''' block is a reporter block in the [[Lists]]
==Case-Sensitivity==
This block is not case-sensitive. For example:
<scratchblocks>
when gf clicked
delete all of [characters v]
add [Bulbasaur] to [characters v]
add [Charmander] to [characters v]
add [Squirtle] to [characters v]
say (item # of [CHARMANDER] in [characters v]) for (2) seconds //this will still say the value "2" for 2 seconds, even though the name is capitalized
</scratchblocks>
This is similar to [[() = ()]], and [[() contains ()? (Lists)|<sb>[ v] contains ()?</sb>]].
==Workaround==
This block can be worked around using the following code, which iterates over the items in the list and checks for the first match:
<scratchblocks>
define find item # of (string1)
set [item number
if <[
repeat until <(item (get [item number]::#0869c2) of [
change [item number
end
end
return (get [item number]::#0869c2)
</scratchblocks>
The custom block would then be used like this:
<scratchblocks>
when gf clicked
delete all of [character names v]
add [Ari] to [character names v]
add [Molly] to [character names v]
add [Stan] to [character names v]
add [Kyle] to [character names v]
add [Kenny] to [character names v]
add [Eric] to [character names v]
add [Molly] to [character names v]
set [item number wanted v] to (find item # of [Molly]::custom) //this would be 2, and not 7
</scratchblocks>
==See also==
*[[index of () in ()]]
*[[last index of () in ()]]
{{DISPLAYTITLE:item # of () in ()}}
{{Blockcat|cat=List|type=Reporter|sc=y}}
|